A backstage calculation can be written as an arrow function instead of a function declaration. Try three short calculations in script.js and check their results in the Console.
An arrow function is another way to store a function in a variable. For a single expression, the expression's value is returned automatically. You will meet function expressions and callbacks in more detail later; for now, compare this with the function declaration you just used.
// Function declaration from the previous lesson
function traditionalAdd(a, b) { return a + b; }
// Arrow function — same result, stored in a variable
const add = (a, b) => a + b;
// Single parameter — parentheses optional
const double = n => n * 2;
// No parameters — empty parentheses required
const greet = () => "Hello!";
// Multi-line body — needs {} and explicit return
const classify = n => {
if (n > 0) return "positive";
if (n < 0) return "negative";
return "zero";
};
console.log(add(2, 3), double(4)); // 5 8
For this exercise, use an arrow function for each calculation. Arrow functions also differ in how they handle this and constructors; those details matter later when you learn objects and classes.
For temperature conversion, Math.round(value * 10) / 10 rounds to one decimal place: scaling by ten makes the first decimal a whole number before rounding. You will explore Math in the built-ins module.
square as an arrow function.n * n from square(n).celsius as an arrow function.(f - 32) * 5 / 9, rounded to one decimal via Math.round(value * 10) / 10.isEven as an arrow function.isEven.5² = 25 | 98°F = 36.7°C | 4 is even: true using all three functions.Arrow function: const fn = (params) => expression;
Omit {} and return for single-expression arrow functions.
Arrow functions with one parameter don't need parentheses: n => n * 2.