0
0
Javascriptprogramming~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Built-in Methods Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Array map with built-in method
What is the output of this code?
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(Math.sqrt);
console.log(doubled);
Javascript
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(Math.sqrt);
console.log(doubled);
A[1, 1.4142135623730951, 1.7320508075688772, 2]
B[2, 4, 6, 8]
C[1, 4, 9, 16]
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Math.sqrt returns the square root of a number.
❓ Predict Output
intermediate
2:00remaining
Output of String built-in method
What is the output of this code?
const text = 'Hello World';
const result = text.toUpperCase();
console.log(result);
Javascript
const text = 'Hello World';
const result = text.toUpperCase();
console.log(result);
A'HELLO WORLD'
B'hello world'
C'Hello World'
DReferenceError
Attempts:
2 left
πŸ’‘ Hint
toUpperCase converts all letters to uppercase.
❓ Predict Output
advanced
2:00remaining
Output of Array filter with built-in method
What is the output of this code?
const values = [10, 15, 20, 25, 30];
const filtered = values.filter(x => x % 20 === 0);
console.log(filtered);
Javascript
const values = [10, 15, 20, 25, 30];
const filtered = values.filter(x => x % 20 === 0);
console.log(filtered);
A[10, 20, 30]
B[20]
C[20, 40]
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
filter keeps elements where the function returns true.
❓ Predict Output
advanced
2:00remaining
Output of Object.keys built-in method
What is the output of this code?
const obj = {a: 1, b: 2, c: 3};
const keys = Object.keys(obj);
console.log(keys);
Javascript
const obj = {a: 1, b: 2, c: 3};
const keys = Object.keys(obj);
console.log(keys);
A['a:1', 'b:2', 'c:3']
B[1, 2, 3]
C['a', 'b', 'c']
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Object.keys returns an array of property names.
❓ Predict Output
expert
3:00remaining
Output of chaining built-in methods
What is the output of this code?
const sentence = '  JavaScript is fun  ';
const result = sentence.trim().split(' ').filter(word => word.length > 2).join('-');
console.log(result);
Javascript
const sentence = '  JavaScript is fun  ';
const result = sentence.trim().split(' ').filter(word => word.length > 2).join('-');
console.log(result);
A'JavaScript-is-fun'
B'JavaScript--is--fun'
C'JavaScript-is-'
D'JavaScript-fun'
Attempts:
2 left
πŸ’‘ Hint
trim removes spaces, split divides words, filter removes short words, join connects with dashes.