Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the function greet.
Javascript
function greet() {
console.log('Hello!');
}
greet[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Forgetting the parentheses and just writing the function name.
Using curly braces or square brackets instead of parentheses.
β Incorrect
To execute a function in JavaScript, you add parentheses after its name, like
greet().2fill in blank
mediumComplete the code to return the sum of two numbers inside the function.
Javascript
function add(a, b) {
return a [1] b;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using subtraction
- instead of addition.Using multiplication or division operators by mistake.
β Incorrect
The plus sign
+ adds two numbers together in JavaScript.3fill in blank
hardFix the error in the function call to correctly pass the argument.
Javascript
function sayName(name) {
console.log('Name:', name);
}
sayName[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Passing the string without quotes, causing a reference error.
Not using parentheses to call the function.
β Incorrect
When calling a function with a string argument, you must put the string in quotes inside parentheses, like
sayName('John').4fill in blank
hardFill both blanks to create a function that returns the square of a number.
Javascript
function square(num) {
return num [1] [2];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using multiplication
* but forgetting to multiply by the number itself.Using the wrong operator or missing the exponent.
β Incorrect
The exponentiation operator
** raises a number to a power. To square a number, use num ** 2.5fill in blank
hardFill the blanks to create a function that filters numbers greater than 10 from an array.
Javascript
function filterGreater(arr) {
return arr.filter(num => num [1] [2]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using equality
== instead of greater than.Using less than
< instead of greater than.β Incorrect
To filter numbers greater than 10, use the greater than operator
> and compare with 10: num > 10.