开发者

How do i set the minimum value to 70 and how can i stop people inputting letters and symbols. And how do i get the running total to add up?

Running Total

function CalculateTotal()
{

    var intCalculateTotal = 0;
    var intMinValue = 70;
    var intInput;
    var boolMoreNumbers = true; 
    var boolCorrectInput = true;

    for (var intCount= 70; intCount<=15; intCount++)
    {


        intInput=parseInt(prompt("Please Enter a number higher          than 70", "")); 


    if (i <=70)
            {
            alert ("Minimum number needs to be 70");
            }



    if (intInput > intMinValue) 
            {

            intCalculateTotal = intCalculateTotal + intMinValue;    

            }


    }

        alert("The running Total is " + intCa开发者_Go百科lculateTotal);
}

Calculate Running Total

 


You can't stop people from putting in letters and symbols... but you can look for them with a regex and put up another alert. Alternatively you can just ignore them - your parseInt will just ignore non-digits and give you the digit-part of the input as though they weren't there.

You code already only adds the int if it's > 70, though you're not alerting the user of this, because instead your code checks that the loop variable is > 70. If you'd like to alert the user, you'd need:

if (intInput <=70)
{
   alert ("Minimum number needs to be 70");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜