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

24th Jun 2018, 10:20 AM
Daniel Cooper
Daniel Cooper - avatar
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
24th Jun 2018, 10:38 AM
Ipang
+ 5
Daniel Cooper hehehe yeah you can choose any number for the limit though. You're welcome, and Thanks mate : )
24th Jun 2018, 9:23 PM
Ipang
+ 4
Thanks for marking my answer mate hehehe : )
24th Jun 2018, 10:01 PM
Ipang
+ 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
24th Jun 2018, 10:25 AM
sairam kamalay
sairam kamalay - avatar
+ 1
Ipang Funny, because 5 is the number I was going for xD
24th Jun 2018, 9:18 PM
Daniel Cooper
Daniel Cooper - avatar
+ 1
but thanks. Had no idea you could use if statements like that.
24th Jun 2018, 9:19 PM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Thanks for what? I should be thanking you
24th Jun 2018, 9:43 PM
Daniel Cooper
Daniel Cooper - avatar
0
Ipang Lol. No problem. And sairam kamalay I wanted to avoid disabling the button, but thanks!
24th Jun 2018, 10:27 PM
Daniel Cooper
Daniel Cooper - avatar
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
24th Jun 2018, 10:40 PM
Daniel Cooper
Daniel Cooper - avatar