-4

I have a question as to why this is not working. Noob question, probably.

var itemCheck = {
    darkBerries: 0
}

var id = darkBerries;

itemcheck . id ++;

Thank you.

  • What happens instead of working? What did you expect to happen? – ctt Aug 17 '18 at 05:23
  • What are you trying to do? What is your desired output? – Saboor Aug 17 '18 at 05:24
  • `itemcheck` is not defined. `itemCheck` is a different variable. `darkBerries` is not defined. Read about [JavaScript objects](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics). – axiac Aug 17 '18 at 05:25

2 Answers2

0
var itemCheck = {
    darkBerries: 0
}

var id = itemCheck.darkBerries;

id ++;
Akbar Soft
  • 1,028
  • 10
  • 19
0

If I understand correctly, you want to increment the darkBerries property using the id variable. To do that you have to save a string in the id and use the brackets notation to access the object's property:

var itemCheck = {
    darkBerries: 0
};

var id = "darkBeries";
itemCheck[id]++;
Angel Politis
  • 10,955
  • 14
  • 48
  • 66