0
0
Javascriptprogramming~10 mins

Function declaration 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 declare a function named greet.

Javascript
function [1]() {
  console.log('Hello!');
}
Drag options to blanks, or click blank then click option'
Agreet
BsayHello
Chello
Dwelcome
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a different function name than 'greet'.
Missing the function name entirely.
2fill in blank
medium

Complete 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'
Aplus
Bsum
Ccalculate
Dadd
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a different function name like 'sum' or 'plus'.
Forgetting to include parameters.
3fill in blank
hard

Fix 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'
Agreet
Bgreet1
C1greet
Dgreet-name
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Starting the function name with a number.
Using hyphens in the function name.
4fill in blank
hard

Fill 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'
Amultiply
B+
C*
Dadd
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using addition operator instead of multiplication.
Using incorrect function names.
5fill in blank
hard

Fill 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'
AgreetUser
BuserName
Dname
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different names for the parameter and inside the template string.
Using incorrect function names.