Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the function before its declaration.
Javascript
console.log([1]()); function greet() { return 'Hello!'; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a variable name that is not declared as a function.
Trying to call a function expression before its assignment.
β Incorrect
The function greet is hoisted, so you can call it before its declaration.
2fill in blank
mediumComplete the code to assign a function expression and call it.
Javascript
const sayHi = [1]() { return 'Hi!'; }; console.log(sayHi());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using incorrect keywords like 'func' or 'def' which are not valid in JavaScript.
Omitting the function keyword entirely.
β Incorrect
Function expressions use the keyword function to assign a function to a variable.
3fill in blank
hardComplete the code to call the function expression correctly.
Javascript
const greet = function() { return 'Hello!'; };
console.log([1]()); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Calling the function expression before it is assigned.
Using a different variable name than the one assigned.
β Incorrect
Function expressions are not hoisted, so call them after assignment. The variable name is greet.
4fill in blank
hardFill both blanks to create a function expression and call it.
Javascript
const add = [1](a, b) [2] a + b; console.log(add(2, 3));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using arrow function syntax incorrectly.
Omitting the return statement inside braces.
β Incorrect
Use function to define the function expression and { return for the body with explicit return.
5fill in blank
hardFill all three blanks to create a function expression and call it.
Javascript
const multiply = [1](x, y) [2] x * y; console.log([3](4, 5));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using arrow function syntax incorrectly.
Calling the function with a wrong name.
β Incorrect
This code defines a function expression named multiply and calls it correctly.