Maybe I’m overthinking this. Will probably end up getting the answer if I just take a break from it for a second but I can’t get my head around it at the moment. Doing Javascript basics, and the problem question relates to amending objects in a function.
Will add the code below.
Sorry if I miss any details out – this is my first time seeking support on this community forum!
The question essentially presents you with object ‘Kitchen’ but with a few ‘issues’ that need sorting to make it read better. I’ve ‘passed’ 6 but failing the 7th requirement.
Requirements are:
- is a function – DONE
- should return a kitchen with the correct keys (hasFridge, favouriteAppliance, food, petName, totalShelves) – DONE
- should change each string to lower case in the object item – DONE
- should delete the hoover property, if present in the object – DONE
- should return the correct total number of shelves (5) – DONE
- should return the correct total number of shelves if only one shelf key is present
✕ AssertionError: expected 5 to equal 3
- should remove other shelf keys – DONE
The object:
let kitchen = {
hasFridge: true,
favouriteAppliance: "KeTtlE",
drinks: "lemoNAdE",
food: "eGgS",
shelvesInCupboards: 3,
shelvesNotInCupboards: 2,
petName: "RhuBarB",
hoover: "DysOn"
};
My code:
function sortTheKitchen(kitchen) {
console.log(kitchen);
delete kitchen.shelvesNotInCupboards
const kitchenItems = {
hasFridge: true,
favouriteAppliance: 'kettle',
food: 'eggs',
petName: 'rhubarb',
drinks: 'lemonade',
shelvesInCupboards: 3
};
for (const key in kitchenItems) {
for (const key1 in kitchen) {
if (key === key1) {
kitchen[key1] = kitchenItems[key]
}
if (key1 === 'hoover') {
delete kitchen[key1]
}
}
}
delete kitchen.shelvesInCupboards
kitchen.totalShelves = 5
return kitchen;
}