JS Small case: 5 students voted for the squad leader

Source: Internet
Author: User

<script>
var array1=new Array ();
var array2=new Array ();
for (Var i=0;i<5;i++)
{
array1[i]=0;
Array2[i]=1;
}
for (Var i=1;i<5;i++)
{
Array2[i]=parseint (array2[i-1]) +1;
}
var fei=0;
var piao=0;
for (Var i=0;i<20;i++)
{
var value=prompt ("First" + (i+1) + "Individual start voting");
var valueint=parseint (value);
if (value!=null&&value!= "" &&!isnan (value) &&value%1==0&&valueInt>0&& VALUEINT&LT;6)
{
Switch (valueint)
{
Case 1:
Array1[0]+=1;
Break
Case 2:
Array1[1]+=1;
Break
Case 3:
Array1[2]+=1;
Break
Case 4:
Array1[3]+=1;
Break
Case 5:
Array1[4]+=1;
Break
}
Piao+=1;
}
Else
{
Fei+=1;
}
}
for (Var i=0;i<10;i++)
{
for (Var j=0;j<=i;j++)
{
if (parseint (Array1[j]) >parseint (Array1[i]))
{
var a=array1[i];
ARRAY1[I]=ARRAY1[J];
Array1[j]=a;
var b=array2[i];
ARRAY2[I]=ARRAY2[J];
Array2[j]=b;
}
}
}
document.write ("Total votes: 20, invalidated:" +fei+ ", number of valid votes:" +piao+ "<br/>");
for (Var i=array1.length-1;i>=0;i--)
{
document.write (array2[i]+ "number of students ranked first" + (5-i) + ", the ticket is:" +array1[i]+ "<br/>");
}

/*if (A1>=A2&&A1>=A3&&A1>=A4&&A1>=A5)
{
Alert ("Class 1th is the Monitor");
}
if (A2>=A1&&A2>=A3&&A2>=A4&&A2>=A5)
{
Alert ("Class 2nd is the Monitor");
}
if (A3>=A1&&A3>=A1&&A3>=A4&&A3>=A5)
{
Alert ("Class 3rd is the Monitor");
}

if (A4>=A1&&A3>=A2&&A4>=A3&&A4>=A5)
{
Alert ("Class 4th is the Monitor");
}

if (A5>=A1&&A5>=A2&&A5>=A3&&A5>=A4)
{
Alert ("Class 5th is the Monitor");
}*/
</script>

JS Small case: 5 students voted for the squad leader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.