Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define 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'.
Forgetting to name the function.
✗ Incorrect
The function name must be 'greet' to match the intended function definition.
2fill in blank
mediumComplete the code to call the function greet.
Javascript
[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function name that was not defined.
Forgetting the parentheses when calling the function.
✗ Incorrect
To call the function named 'greet', use 'greet()'.
3fill in blank
hardFix the error in the function to correctly log the parameter.
Javascript
function greet(name) {
console.log([1]);
}
greet('Alice'); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Name' instead of 'name'.
Logging the string 'name' instead of the variable.
✗ Incorrect
The parameter is named 'name' with lowercase, so use 'name' inside the function.
4fill in blank
hardFill both blanks to create a function that returns the sum of two numbers.
Javascript
function add([1], [2]) { return a + b; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names that don't match the return statement.
Using unrelated variable names.
✗ Incorrect
The function parameters must be 'a' and 'b' to match the return statement.
5fill in blank
hardFill all three blanks to create a function that checks if a number is positive.
Javascript
function isPositive([1]) { if (num [2] 0) { return [3]; } else { return false; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than 'num'.
Using '<' instead of '>' in the condition.
Returning false instead of true when the condition is met.
✗ Incorrect
The parameter is 'num', the condition checks if num > 0, and returns true if so.