Changing
JavaScript · Unit 7: Objects
- Full plan
- JavaScript
- 11 exercises
To change a property, give it a new value with =. If the property didn't exist, it gets created.
const phone = { credit: 50 };
phone.credit = 80;
phone.plan = "basic";
console.log(phone);Prints
{ credit: 80, plan: 'basic' }The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Predict the output
What does this code print?
3. Complete the code
Leo crashed in the game. Complete it so he has one life less.
4. Multiple choice
If
pwas created withconst p = { age: 17 };, which of these lines crashes?5. Predict the output
What does this code print?
6. Predict the output
What does this code print?
7. Complete the code
Complete the condition to know whether the store carries milk.
8. Predict the output
What does this code print?
9. Put the lines in order
Order the function that adds a year to the person and returns, for example, "Ava: 18".
10. Find the bug
This program should add one to the item if it's already in stock, or add it with 1 if it isn't. With the bread it should print
{ bread: 6 }. Which line has the error?11. Find the case that fails
add(stock, item)should add one to the item and return how many there are now, like"bread: 6". If the item wasn't there, it adds it with 1. Which call makes it fail?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.