Home > front end >  Web development small white for help
Web development small white for help

Time:12-05

A great god, please help to see why the code, only hint input array but does not perform the follow-up calculation

CodePudding user response:

Prompt returns the string, use the split to separate the get array

CodePudding user response:

Window. The onl oad=function () {
Var scores;
Scores=prompt (" hello ");
Var xx=scores. The split (", ");
Var s=0, aver=0, low=0;
For (var I=0; I & lt; Xx. Length; I++) {
S=s + parseInt (xx [I]);
If (parseInt (xx) [I] <60) {
Low++;
}
}
Aver=s/xx. Length;
Alert (" zongfen: "+ s);
Alert (" pingjun: "+ aver);
Alert (" nujige: "+ low);
}

CodePudding user response:

Prompt return type string, even if you use the array, your scores [0] is the first character in the string, you
I don't know what are you going to in a prompt one-time input all the scores, commas, perhaps? But even there are seven prompt didn't also the way of digital computing, such as you enter the first student's result is 100, the second is 50100 + 50 become string together, or 10050, should be the need to turn the data type,
Can try the above code, enter the score with commas

CodePudding user response:

You that return s back out, directly, and does not perform the alter ()
  • Related