Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet that takes one parameter called name.
Javascript
function greet([1]) {
console.log(`Hello, ${name}!`);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a different parameter name than the one used inside the function.
Forgetting to add any parameter.
β Incorrect
The function parameter should be named 'name' to match the usage inside the function.
2fill in blank
mediumComplete the code to call the function greet with the argument 'Alice'.
Javascript
greet([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Passing the string without quotes, which causes a reference error.
Using a variable name instead of a string.
β Incorrect
When passing a string argument, it must be enclosed in quotes.
3fill in blank
hardFix the error in the function definition to correctly set a default value for the parameter age.
Javascript
function showAge(age [1] 18) { console.log(`Age is ${age}`); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '==' instead of '=' for default parameters.
Using ':' or '=>' which are invalid here.
β Incorrect
The correct syntax for default parameters uses a single equals sign '='.
4fill in blank
hardFill the three blanks to define a function multiply that takes two parameters and returns their product.
Javascript
function multiply([1], [2]) { return [1] [3] [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using the wrong operator like '+' instead of '*'.
Mixing up parameter names.
β Incorrect
The function parameters are 'a' and 'b', and the operator to multiply is '*'.
5fill in blank
hardFill both blanks to create a function that returns an object with keys as parameter names and values as their values.
Javascript
function createObject([1], [2]) { return { [1]: [1], [2]: [2] }; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using different names for keys and values.
Forgetting to include both parameters.
β Incorrect
The parameters are 'x' and 'y'. The object keys and values use the same names.