Add Key-Value Pairs to JavaScript Objects

Add Key-Value Pairs to JavaScript Objects
0

#1

Tell us what’s happening:

How to do it ?

Your code so far


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

// change code below this line

// 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/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/add-key-value-pairs-to-javascript-objects


#2

Add three more entries: bananas with a value of 13, grapes with a value of 35, and strawberries with a value of 27

Add new foods to the foods object.

/* 
    foods[<<key>>] = <<value>>
*/

foods['blueberries'] = 99;

#3

Hi, you can do this by using dot notation. So the answer is:

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

#4

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);


#5

Do you have an issue with that code?