Javascript - How to save prompt input into array

后端 未结 4 465
日久生厌
日久生厌 2021-01-23 10:12

I`m having some issue with Javascript. We just started to study it a couple weeks ago and I have to do a work for class:

Need to do a prompt. get 10 numbers input (10 gr

4条回答
  •  长情又很酷
    2021-01-23 11:05

    See the explanations in comments:

    var arr = [];                               // define our array
    
    for (var i = 0; i < 10; i++) {              // loop 10 times
      arr.push(prompt('Enter grade ' + (i+1))); // push the value into the array
    }
    
    alert('Full array: ' + arr.join(', '));     // alert the results

提交回复
热议问题