0
0
Javascriptprogramming~10 mins

Adding and removing properties in Javascript - Interactive Code Practice

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

Complete 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'
Aage
Blength
Cpush
Dpop
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.
2fill in blank
medium

Complete 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'
Acolor
Bbrand
Clength
Dmodel
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Trying to assign null or undefined instead of deleting.
Deleting a property that does not exist.
3fill in blank
hard

Fix 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'
A[height]
B.height
C['height']
Dheight
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using brackets without quotes for property names.
Trying to assign a value without dot or bracket notation.
4fill in blank
hard

Fill 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'
A.score
B['score']
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mixing dot and bracket notation incorrectly.
Forgetting quotes in bracket notation.
5fill in blank
hard

Fill 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'
A.name
B['name']
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using bracket notation without quotes.
Trying to delete with dot notation without quotes.