Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an arrow function that adds two numbers.
Javascript
const add = (a, b) => [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to include both parameters.
β Incorrect
The arrow function should return the sum of a and b, so use 'a + b'.
2fill in blank
mediumComplete the code to create an arrow function that returns the square of a number.
Javascript
const square = x => [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Adding the number to itself instead of multiplying.
Dividing or subtracting instead of multiplying.
β Incorrect
To get the square, multiply the number by itself using 'x * x'.
3fill in blank
hardFix the error in the arrow function that returns the length of a string.
Javascript
const length = str => [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using parentheses after length like a function call.
Using incorrect property names like size.
β Incorrect
In JavaScript, string length is accessed as a property without parentheses: 'str.length'.
4fill in blank
hardFill both blanks to create an arrow function that filters an array for numbers greater than 10.
Javascript
const filterLarge = arr => arr.filter(num => num [1] [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '<' instead of '>' for the comparison.
Using the wrong number for comparison.
β Incorrect
To filter numbers greater than 10, use 'num > 10' inside the filter.
5fill in blank
hardFill all three blanks to create an arrow function that maps an array to uppercase strings and filters those starting with 'A'.
Javascript
const process = arr => arr.map(str => str.[1]()).filter(str => str.[2](0) === [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'toLowerCase' instead of 'toUpperCase'.
Using incorrect methods to get the first character.
Comparing to the wrong character.
β Incorrect
Use 'toUpperCase()' to convert strings, 'charAt(0)' to get first letter, and compare to 'A'.