var house = {
areas: [{
livingRoom: {
items: ['tv','sofa']
},
bedroomOne: {
items: ['bed','washing machine'],
windows: 3
},
bedroomTwo:{
items: ['bed','bed','desk'],
windows: 4
},
kitchen:{
items: ['fridge','broken chair']
}
}],
garden: [true, 'Red Rose'],
garage: {
car: {
color: 'red',
wheels: 4,
honk: ()=>{alert("Beep")}
}
}
}
Please check the JS Console for the output to the following questions
let houseAreas = Object.keys(house.areas[0]).length;
console.log(houseAreas);
house.areas[0].livingRoom.items.push("dining table");
console.log(house.areas[0].livingRoom.items);
house.areas[0].kitchen.items.push("stove");
console.log(house.areas[0].kitchen.items);
house.areas[0].bedroomOne.items.pop();
console.log(house.areas[0].bedroomOne.items);
let rooms = Object.keys(house.areas[0]);
let beds = 0;
for (let i = 0; i < rooms.length; i++) {
let roomItems = house.areas[0][rooms[i]]["items"];
for (let j = 0; j < roomItems.length; j++) {
if(roomItems[j] == "bed") {
beds++
}
}
};
console.log(beds);
house.garage.car.color = "blue";
console.log(house.garage.car.color);
house.garage.car2 = {
color: 'green',
wheels: 4,
honk: ()=>{alert("Beep")}
};
console.log(house.garage);
house.garage.car2.honk();
house.areas[0].kitchen.items.splice(1,1,"new chair");
console.log(house.areas[0].kitchen.items);
if (house.garden[0]) {
console.log(house.garden[1]);
};