0
Limit the counter?
Is there a way I can limit the variable or somehow make it stop counting when it reaches a certain number? Everything I try just kinda crashes the Sololearn app. https://code.sololearn.com/WQtkfnr8ukt3/?ref=app
9 Answers
+ 4
Adjust the value checked as necessary.
function Add() {
if(i == 5) return false;
i++;
document.getElementById("Output").innerHTML = i;
}
function Subtract() {
if(i == -5) return false;
i--;
document.getElementById("Output").innerHTML = i;
}
Hth, cmiiw
+ 5
Daniel Cooper hehehe yeah you can choose any number for the limit though.
You're welcome, and Thanks mate : )
+ 4
Thanks for marking my answer mate hehehe : )
+ 3
use an if statement inside your add and subtract function to check if is equal to a certain number
if satisfied disable the button
https://code.sololearn.com/W5j4ZeuQeS4O/?ref=app
+ 1
Ipang Funny, because 5 is the number I was going for xD
+ 1
but thanks. Had no idea you could use if statements like that.
+ 1
Thanks for what?
I should be thanking you
0
Ipang Lol. No problem.
And sairam kamalay
I wanted to avoid disabling the button, but thanks!
0
ok, new problem.
I want it to turn red when it reaches the specified number, but nothing I try works.
Why am I so bad at this xD