Functions are named blocks of code you can call over and over. They accept parameters and can return a value.
function greet(name) {
return "Hello, " + name + "!"
}
console.log(greet("Alice")) // Hello, Alice!
console.log(greet("Bob")) // Hello, Bob!
Without return, the function returns undefined:
function noReturn() {
console.log("I don't return anything")
}
const result = noReturn() // undefined
function rectangle(width, height) {
return width * height
}
console.log(rectangle(4, 5)) // 20
Write a function celsiusToFahrenheit(deg) that converts Celsius to Fahrenheit.
Formula: F = (C × 9/5) + 32
Click "Run" to execute your code.