Need help with syntax eroors


#1

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/0/5?curriculum_id=506324b3a7dffd00020bf661


.// Nicely written function:
var calculate = function (number) {
    var val = number * 10;
    console.log(val);
};

// Badly written function with syntax errors!

greeting var func{name} console.log(name)}


#2

This is supposed to be a hands-on exercise. Study the example (the nicely written function). Identify the components and then study the badly written function. Start from left to right.

Study notes:

What are the components of a function?

keyword
parameter
body

Study the good example. Notice the keyword, followed by the parameter, followed by the body (often referred to as the block). The function itself is on the right side of the equal sign (the assignment operator). It is known as an expression and in this instance, it is an anonymous function.

In order to invoke the function we're going to need a name. Study the above example and notice the var declaration that defines the variable, calculate? Try the same in example needing repair. Then assign the function expression with the syntax corrected, and you're done. Then the only thing left is to run it.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.