Asked to:
‘Iterate through the staff nested inside the restaurant object, and add their names to the staffNames array.’
My solution keeps getting rejected with this error:
‘Use a declaration keyword when declaring your key variable’
Feel like I’m going mad as I’ve definitely declared the variable.
Code below, what I added is in bold; the rest is the original code.
const restaurant = {
tables: 32,
staff: {
chef: "Andy",
waiter: "Bob",
manager: "Charlie"
},
cuisine: "Italian",
isOpen: true
};
const staffNames = []
**for (key in restaurant.staff){
const value = restaurant.staff[key]
staffNames.push(value)
}**
3
Answers
You haven’t. You’ve just started assigning values to it.
To declare a variable you need to use a keyword like
const
orlet
(orvar
, which isn’t recommended these days, or a function declaration which wouldn’t be appropriate here.)Aside: Your code would probably be better written as:
You need to declare the variable
key
in your for loop. Try this:Working fine!