Implement the following user story:
It’s done when the customerOrder
object has three properties that store the drink’s name, the number of sugars, and a Boolean indicating whether the order is ready.
It’s done when the drink name and the number of sugars is logged to the console.
It’s done when, if the order is ready, the message "Ready for pick-up"
logs.
It’s done when, if the order is not ready, the message "Still in order queue"
logs.
How can we use dot notation or bracket notation to access an object’s values?
If you have completed this activity, work through the following challenge to further your knowledge:
for...in
statement? How can you use it to iterate over an objectβs properties?Use Google or another search engine to research this.
// Object customerDrink with three properties
var customerDrink = {
name: "coffee",
sugars: 3,
isReady: true
};
// This logs the entire object
console.log(customerDrink);
// Note that in dot notation, the name of the object is followed by the key
if (customerDrink.isReady) {
console.log("Ready for pick-up: " + customerDrink.name + " with " + customerDrink.sugars + " sugars.");
// Note that in bracket notation, the key is inside brackets and surrounded by quotes
} else {
console.log("Still in order queue: " + customerDrink["name"] + " with " + customerDrink["sugars"] + " sugars.");
}