Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a function named greet.
Javascript
function [1]() { console.log('Hello!'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a different function name than 'greet'.
Missing the function name entirely.
β Incorrect
The function name should be greet as requested.
2fill in blank
mediumComplete the code to declare a function named add that takes two parameters.
Javascript
function [1](a, b) { return a + b; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a different function name like 'sum' or 'plus'.
Forgetting to include parameters.
β Incorrect
The function should be named add as per the instruction.
3fill in blank
hardFix the error in the function declaration to make it valid.
Javascript
function [1](name) { console.log('Hi, ' + name); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Starting the function name with a number.
Using hyphens in the function name.
β Incorrect
Function names cannot start with a number or contain hyphens. greet is a valid name.
4fill in blank
hardFill both blanks to declare a function named multiply that returns the product of two numbers.
Javascript
function [1](x, y) { return x [2] y; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using addition operator instead of multiplication.
Using incorrect function names.
β Incorrect
The function name should be multiply and the operator for multiplication is *.
5fill in blank
hardFill all three blanks to declare a function named greetUser that takes a name and returns a greeting message.
Javascript
function [1]([2]) { return `Hello, $[3]!`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using different names for the parameter and inside the template string.
Using incorrect function names.
β Incorrect
The function name is greetUser. The parameter is name, and the template uses name to greet.