I’m new to coding so please forgive me it this is simple and any bad code. The question is:
Here’s an example problematic kitchen
const kitchen = {
hasFridge: true,
favouriteAppliance: 'KeTtlE',
food: 'eGgS',
shelvesInCupboards: 3,
shelvesNotInCupboards: 2,
petName: 'RhuBarB',
hoover: 'DysOn'
};
To sort out our kitchen:
- Fix the jumbled string values – replace them all with versions that are all lowercase
- Remove the hoover property – hoovers don’t belong in the kitchen
- We only need to know the total number of shelves. If shelvesInCupboards and/or shelvesNotInCupboards are present, delete these keys
- Add a key of totalShelves which is equal to the sum of the values that were under shelvesInCupboards and shelvesNotInCupboards.
A fixed-up version of the above example kitchen should look like this, though remember that object properties are not ordered, so it doesn’t matter if your properties appear to be in a different order.
const kitchen = {
hasFridge: true,
favouriteAppliance: 'kettle',
food: "eggs",
petName: 'rhubarb',
totalShelves: 5
};
The preset code is:
function sortTheKitchen(kitchen) {
// Don't change the code below this line
return kitchen;
}
I’ve gotten up to here so far but I am confused about the how to tackle parts 3 and 4 of sorting out the kitchen.
function sortTheKitchen(kitchen) {
for (let key in kitchen) {
if (typeof kitchen[key] === 'string') {
kitchen[key] = kitchen[key].toLowerCase();
}
}
delete kitchen.hoover;
kitchen.totalShelves = (kitchen.shelvesInCupboards + kitchen.shelvesNotInCupboards);
delete kitchen.shelvesInCupboards;
delete kitchen.shelvesNotInCupboards;
return kitchen
}
Thanks for any help you can provide.