Need help with syntax eroors


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

// Badly written function with syntax errors!

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


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?


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.


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