Search code examples
javascriptint

Add 1 to a value and log it in the console


Okay so I have a var that I want to be used in a calculation(I just want to add +1 to the number inside the var) and IDK how to do it cuz when I do it the way I did in my code it won't update the var it only adds one but it won't add more so If I run the script or do it multiple times it won't add 1 to it.

if(msg.content == "-testnum")
  {
    var numberino = 0;
    numberino = numberino + 1;
    msg.reply(numberino)
    console.info(numberino + 1);
  }


Solution

  • I think the problem might be that you are running the code multiple times, so every single time you just reset your variable. However, I'm not 100% sure since its not clear if this is just a piece of the code or it is the whole code. If it is just a piece of the code however, and it is inside a loop, don't declare the variable inside the loop braces, otherwise whenever the loop runs over the variable var numberino = 0;, it will reset.