Home > front end >  The inside of the JS, don't know how to use a while loop to write
The inside of the JS, don't know how to use a while loop to write

Time:09-15

Page looping pop-up box, stop until the user input - 1 pop-up box, the user input data into an array, and descending sort an array to exclude 1,

CodePudding user response:

Var input, arr=[];
While (input!==1) {
Input=Number (prompt (" please enter the Number));
If (isNaN (input)) {
Alert (" please enter the legal digital ')
} else {
Arr. Unshift (input)
}
}
Var res=arr. Slice (1);
Res. Sort ((a, b)=& gt; A - b)

CodePudding user response:

 
Var input;
var arr=[];
While ((input=parseFloat (prompt (" please enter the number ", "")))!=1) {
Arr. Push (input);
}
Arr. Sort (function (a, b) {
Return b - a;
});
Alert (arr);

CodePudding user response:

Thank you
  • Related