0
0
Javascriptprogramming~10 mins

Function expression 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 create a function expression that returns the sum of two numbers.

Javascript
const add = function(a, b) { return a [1] b; }; console.log(add(2, 3));
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to return the result.
2fill in blank
medium

Complete the code to assign an anonymous function to the variable greet that returns 'Hello!'.

Javascript
const greet = [1]() { return 'Hello!'; }; console.log(greet());
Drag options to blanks, or click blank then click option'
Afunction
Bfun
Cfunc
Ddef
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using incorrect keywords like 'fun' or 'def'.
Omitting the function keyword.
3fill in blank
hard

Fix the error in the function expression syntax.

Javascript
const multiply = function(a, b) [1] return a * b; }; console.log(multiply(4, 5));
Drag options to blanks, or click blank then click option'
A<
B(
C[
D{
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses or brackets instead of curly braces.
Missing the opening brace.
4fill in blank
hard

Complete the code to create a function expression that returns the square of a number.

Javascript
const square = function(num) { return num [1] 2; }; console.log(square(6));
Drag options to blanks, or click blank then click option'
A{
B**
C*
D(
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using multiplication * instead of exponentiation **.
Forgetting the opening brace.
5fill in blank
hard

Fill both blanks to create a function expression that filters an array to keep only even numbers.

Javascript
const evens = numbers.filter(function([1]) { return [2] % 2 === 0; }); console.log(evens);
Drag options to blanks, or click blank then click option'
Anum
B{
Ditem
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using inconsistent parameter names.
Forgetting the opening brace.
Incorrect modulo condition.