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

Tell us what’s happening:

Why does my code not fit the task?
It says “The definition of the foods object should not be changed.”
Could you please tell me, I just don’t understand it.

Your code so far

let foods = {
  apples: 25,
  oranges: 32,
  plums: 28
};
// change code below this line
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

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

This is the original code

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

// Only change code below this line

// Only change code above this line

console.log(foods);

It looks like you may have copied an old version of the challenge starting code from somewhere.

You could also use the more common way, the dot-notation:

foods.bananas = 13; this updates or creates a key/value pair

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.