Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an object with a property 'name' set to 'Alice'.
Javascript
const person = { name: [1] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Forgetting quotes around string values.
Using the property name instead of the value.
β Incorrect
The property value must be a string, so it needs quotes around 'Alice'.
2fill in blank
mediumComplete the code to access the 'age' property from the object 'user'.
Javascript
const age = user[1]age; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using incorrect symbols like '->' or '::'.
Using brackets without quotes.
β Incorrect
Use dot notation to access properties in JavaScript objects.
3fill in blank
hardFix the error in the code to add a new property 'city' with value 'Paris' to the object 'location'.
Javascript
location[1]city = 'Paris';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using arrow or double colon symbols.
Trying to use brackets without quotes.
β Incorrect
Use dot notation to add or update properties in an object.
4fill in blank
hardFill both blanks to create an object 'scores' with keys as player names and values as their points, but only include players with points greater than 10.
Javascript
const scores = {};
for (const player of players) {
if (player.points > 10) {
scores[[1]] = [2];
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using wrong property names like score or value.
Mixing keys and values.
β Incorrect
Use player.name as key and player.points as value to build the object with correct data.
5fill in blank
hardFill all three blanks to create a function that returns an object with keys as uppercase names and values as ages, but only for people older than 18.
Javascript
function adultAges(people) {
return people.reduce((acc, [1]) => {
if ([2].age > 18) {
acc[[3]] = [2].age;
}
return acc;
}, {});
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using different variable names inconsistently.
Not converting names to uppercase.
Mixing parameter names in different places.
β Incorrect
Use 'p' as the parameter, check p.age, and use p.name.toUpperCase() as key to build the object.