For loop four elements: initial condition, cyclic condition, loop body, state change.
1. for (Var a=i;i<=aa;i++)
{
Loop Body (example sum=sum+i sum is output)
}
Examples
1-20 off, not a penny.
20-30 off 10 points per pass
30-40 off/off 20
40-49 off 30 points per pass
50 off 100 points
Enter the score for the number of levels:
<body>
Using the for nested if language, using if nesting for handling level issues
<input type= "number" id= "Guan"/>
<input type= "button" value= "Input off fraction" onclick= "Shuru ()"/><br/>
For nested IF statements
<input type= "number" id= "Gan"/>
<input type= "button" value= "Enter level view Score" onclick= "ABC ()"/>
If nested for statement
</body>
<script>
function Shuru ()
{
var aa=parsefloat (document.getElementById ("Guan"). Value)
if (aa!= "")
{
if (aa>0&&aa<=50&&aa%1==0)
{
Sum=0
for (Var i=1;i<=aa;i++)
{
if (aa>0&&aa<=20)
{
Sum+=i
}
else if (aa>=21&&aa<=30)
{
if (i<=20)
{
Sum+=i
}
Else
{
sum+=10
}
}
else if (aa>=31&&aa<=40)
{
if (i<=20)
{
Sum+=i
}
else if (i<30)
{
sum+=10
}
Else
{
Sum+=20
}
}
else if (aa<=49&&aa>=41)
{
if (i<=20)
{
Sum+=i
}
else if (i<30)
{
sum+=10
}
else if (i<40)
{
Sum+=20
}
Else
{
Sum+=30
}
}
Else
{
sum==880
}
}
Alert (SUM)
}
Else
{
Alert ("Please enter the correct level")
}
}
}
function ABC ()
{
var aa=parsefloat (document.getElementById ("Gan"). Value);
if (aa!= "")
{
if (aa>0&&aa<=50&&aa%1==0)
{
if (aa>0&&aa<=20)
{
var sum=0
for (Var i=1;i<=aa;i++)
{
Sum+=i
}
Alert (SUM)
}
else if (aa>=21&&aa<=30)
{
var sum=210
for (Var i=21;i<=aa;i++)
{
sum+=10
}
Alert (SUM)
}
else if (aa>=31&&aa<=40)
{
var sum=310
for (Var i=31;i<=aa;i++)
{
Sum+=20
}
Alert (SUM)
}
else if (aa>=41&&aa<=49)
{
var sum=510
for (Var i=41;i<=aa;i++)
{
Sum+=30
}
Alert (SUM)
}
Else
{
Alert (880)
}
}
Else
{
Alert ("Level input error")
}
}
}
</script>
JS practice for the FOR Loop statement