Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  19] [ 3]  / answers: 1 / hits: 15895  / 12 Years ago, fri, september 14, 2012, 12:00:00

Im trying to make a talent calculator of sorts, clicking the 'skill' will decrease this variable and right-clicking will increase the variable.



The problem i have is i want the variable to be limited from going over 50 or below 0.



Now ive googled and searched here for variable limits and max integers but nothing gives me an idea how to do this, i think im wording my searches wrong.



Could someone give me an idea how to do this or point me in the right direction please, thanks.



Variable im using:



  var a=50;
function decrease(){a--;document.getElementById('boldstuff').innerHTML= +a;}
function increase(){a++;document.getElementById('boldstuff').innerHTML= +a;}

More From » html

 Answers
42

In function decrease after a-- add



if (a < 0)
a = 0;


And in increase:



if (a > 50)
a = 50;


Or use Math.min(value, minValue) and Math.max(value, maxValue).


[#83082] Wednesday, September 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;