0
0
Javascriptprogramming~10 mins

Function parameters in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Amessage
Bname
Cgreeting
Duser
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a different parameter name than the one used inside the function.
Forgetting to add any parameter.
2fill in blank
medium

Complete the code to call the function greet with the argument 'Alice'.

Javascript
greet([1]);
Drag options to blanks, or click blank then click option'
AAlice
B"Alice"
C'Alice'
Dname
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Passing the string without quotes, which causes a reference error.
Using a variable name instead of a string.
3fill in blank
hard

Fix 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'
A=
B==
C:
D=>
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using '==' instead of '=' for default parameters.
Using ':' or '=>' which are invalid here.
4fill in blank
hard

Fill 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'
Aa
Bb
C*
D+
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the wrong operator like '+' instead of '*'.
Mixing up parameter names.
5fill in blank
hard

Fill 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'
Ax
By
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different names for keys and values.
Forgetting to include both parameters.