Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a new property age with value 25 to the object.
Javascript
const person = { name: 'Alice' };
person.[1] = 25; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using array methods like push or pop on an object.
Trying to assign a value to a method name.
β Incorrect
To add a new property to an object, use dot notation with the property name. Here,
person.age = 25; adds the property age.2fill in blank
mediumComplete the code to remove the property color from the object.
Javascript
const car = { brand: 'Toyota', color: 'red' };
delete car.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Trying to assign
null or undefined instead of deleting.Deleting a property that does not exist.
β Incorrect
The
delete operator removes a property from an object. Here, delete car.color; removes the color property.3fill in blank
hardFix the error in the code to correctly add a property height with value 180.
Javascript
const obj = {};
obj[1] = 180; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using brackets without quotes for property names.
Trying to assign a value without dot or bracket notation.
β Incorrect
To add a property using dot notation, use a dot followed by the property name without quotes or brackets. So,
obj.height = 180; works correctly.4fill in blank
hardFill both blanks to add a property score with value 100 and then remove it.
Javascript
const game = {};
game[1] = 100;
delete game[2]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Mixing dot and bracket notation incorrectly.
Forgetting quotes in bracket notation.
β Incorrect
You can add a property using dot notation:
game.score = 100;. To delete it using bracket notation: delete game['score'];.5fill in blank
hardFill all three blanks to add a property name with value 'Bob', update it to 'Robert', and then remove it.
Javascript
const user = {};
user[1] = 'Bob';
user[2] = 'Robert';
delete user[3]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using bracket notation without quotes.
Trying to delete with dot notation without quotes.
β Incorrect
Add and update the property using dot notation:
user.name = 'Bob'; user.name = 'Robert';. Remove it using bracket notation: delete user['name'];.