0
0
Javascriptprogramming~10 mins

Why built-in methods are useful in Javascript - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the string to uppercase using a built-in method.

Javascript
const word = 'hello';
const upperWord = word.[1]();
console.log(upperWord);
Drag options to blanks, or click blank then click option'
AtoLowerCase
BtoUpperCase
Ctrim
Dsplit
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using toLowerCase() instead of toUpperCase()
Trying to use a method that doesn't change case
2fill in blank
medium

Complete the code to find the length of the array using a built-in property.

Javascript
const fruits = ['apple', 'banana', 'cherry'];
const count = fruits[1];
console.log(count);
Drag options to blanks, or click blank then click option'
A.length()
B.size
C.length
D.count
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using .length() with parentheses
Using .size or .count which are not valid for arrays
3fill in blank
hard

Fix the error in the code to join array elements into a string separated by commas.

Javascript
const colors = ['red', 'green', 'blue'];
const result = colors.[1](',');
console.log(result);
Drag options to blanks, or click blank then click option'
Ajoin
Bsplit
Cconcat
Dpush
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using split() which breaks strings into arrays
Using concat() which merges arrays but not with separators
4fill in blank
hard

Fill both blanks to create an object with keys as words and values as their lengths, only for words longer than 3 letters.

Javascript
const words = ['cat', 'elephant', 'dog', 'lion'];
const lengths = Object.fromEntries(words.filter(word => word.length > 3).map(word => [[1], [2]]));
console.log(lengths);
Drag options to blanks, or click blank then click option'
Aword
Bword.length
Cword.length()
Dword.toString()
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using word.length() which is not a function
Using word.toString() which returns the word itself
5fill in blank
hard

Fill all three blanks to create a new array with uppercase words that have length greater than 3.

Javascript
const words = ['sun', 'moon', 'star', 'sky'];
const result = words.filter(word => word.[1] > [2]).map(word => word.[3]());
console.log(result);
Drag options to blanks, or click blank then click option'
Alength
B3
CtoUpperCase
DtoLowerCase
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using length() instead of length
Using toLowerCase() instead of toUpperCase()