Basic Data Structures: Add Key-Value Pairs to JavaScript Objects

Tell us what’s happening:

both answers are not working for this challenge, any help ?
this is the only problem :

The key-value pairs should be set using dot or bracket notation.

Your code so far


let foods = {
apples: 25,
oranges: 32,
plums: 28
};

// change code below this line
//my answer 1
foods = {...foods, bananas:13, grapes: 35, strawberries:27};
//my answer 2
foods.bananas = 13;
foods.grapes = 35;
foods.strawberries =27;
//after viewing the website answer
foods["bananas"] = 13;
foods["grapes"] = 35;
foods["strawberries"] = 27;
// change code above this line

console.log(foods);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Add Key-Value Pairs to JavaScript Objects

Link to the challenge:

The tests are picking up your first answer, which is not using bracket or dot notation as asked, and mark it as wrong.

Try removing/comment those lines and see if you can pass the challenge. :smile:

thanks , but i commented all the answers one by one in order to check , it’s not commented here to make it more readable.

Hi. What is your problem exactly? your code should be like this:

let foods = {
  apples: 25,
  oranges: 32,
  plums: 28
};

// Answer

foods.bananas = 13;
foods.grapes = 35;
foods.strawberries = 27;

// ***

console.log(foods);

You have to completely remove the code for the first answer you have, it is not enough to comment it out. Other than that both answer 2 and 3 should pass.