Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get all keys from the object.
Javascript
const obj = {a: 1, b: 2, c: 3};
const keys = Object.[1](obj);
console.log(keys); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using Object.values instead of Object.keys
Trying to call a non-existent method like Object.getKeys
β Incorrect
Object.keys(obj) returns an array of the object's own property names (keys).
2fill in blank
mediumComplete the code to get all values from the object.
Javascript
const obj = {x: 10, y: 20, z: 30};
const vals = Object.[1](obj);
console.log(vals); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using Object.keys instead of Object.values
Trying to call a non-existent method like Object.getValues
β Incorrect
Object.values(obj) returns an array of the object's own property values.
3fill in blank
hardFix the error in the code to get entries from the object.
Javascript
const obj = {name: 'Alice', age: 25};
const entries = Object.[1](obj);
console.log(entries); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using Object.getEntries which does not exist
Using Object.keys or Object.values instead of Object.entries
β Incorrect
Object.entries(obj) returns an array of [key, value] pairs from the object.
4fill in blank
hardFill both blanks to create an object from entries and get its keys.
Javascript
const entries = [['a', 1], ['b', 2]]; const obj = Object.[1](entries); const keys = Object.[2](obj); console.log(keys);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using Object.entries instead of Object.fromEntries
Using Object.values instead of Object.keys to get keys
β Incorrect
Object.fromEntries creates an object from key-value pairs. Object.keys gets the keys of that object.
5fill in blank
hardFill all three blanks to filter object keys with values greater than 10.
Javascript
const data = {a: 5, b: 15, c: 25};
const filteredKeys = Object.[1](data)
.filter(key => data[key] [2] 10)
.map(key => key.[3]());
console.log(filteredKeys); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using Object.values instead of Object.keys to get keys
Using '<' instead of '>' in filter condition
Using toLowerCase instead of toUpperCase
β Incorrect
Object.keys gets keys, filter selects keys with values > 10, map converts keys to uppercase.