Ask coding questions

← Back to all posts
doing math on a variable
AlecBritton

I am trying to make a simple number guessing game, the game itself works, but I wanted to make an attempt limit at 3. I made a variable for the turns as 3 and make the variable a number value, however, on my if statement i make the logic that if the guess value doesn't equal the random number, then it would subtract 1 from the turns value, then when the turns variable hit zero, it would give a message that you had no more attempts. But when I do that logic it comes up as a unexpected number or undefined. What would be a solution to this?

Answered by TheDNAHero [earned 5 cycles]
View Answer
Voters
AlecBritton
Comments
hotnewtop
TheDNAHero

Instead of doing
turns=2
Do
turns-=1

AlecBritton

@TheDNAHero that fixed my issue. Thanks!