Need Help with this JavaScript Code

Help

Hi, so I was in this course in javascript here, and i thought… how to make it where when the program run’s, it subtracts it by 1 or 1 %. This is my code:

const robot = { model: '1E78V2', energyLevel: 99, provideInfo() { return `I am ${this.model} and my current energy level is ${this.energyLevel}.` } }; console.log(robot.provideInfo());

What I mean by is, if the energyLevel is set to 100, and i run it 4 times, it automaticlly subtracts 4. (or the amount the user click run)

Thanks

Hi @umariscool

Each time the user clicks run, the code is reset and ran as it is, so afaik, at least in this case, there isn’t a way to transfer that state between runs, instead you could have a function that decreases the energyLevel each time it is called?

-Lyall :slightly_smiling_face:

Hey Lyall

Thanks for reaching out, but can you please elaborate more about the function calling?

Thanks
Umar

When you call a function it just means the code in the function executes(runs)

1 Like