0
私は以前同様の質問をしましたが、私は明確ではなかった、私はここで正しい質問をする方法を学んでいる。私は、配列のサイズとなる数値を入力するようユーザーに促しています。そして、ループして、以前に宣言したサイズに達するまで数値で配列を埋めるようにします。私の質問は、適切にユーザーの入力で配列を格納する方法です。プロンプトでアレイの格納
function getNumber() {
var el = document.getElementById("demo");
// Get the user's input and convert it to a number
var size = parseInt(prompt("Please enter the size of the array"),10);
var entries = parseInt(prompt("Enter an integer"),10);
var userInput = new Array();
while (entries < size){
var entries = parseInt(prompt("Enter an integer"),10);
userInput.push(entries);
userInput = entries.split(" ");
}
// Store the user's input to our global variable
//userInput[] = entries;
// Set up a string that will become the output.
//display iterations
el.textContent = userInput[entries];
}
を、ここでは' –
: 'USERINPUT = entries.split( ""); 'あなたはあなたの' userInput'値をオーバーライドします。 –
ユーザが「3」のサイズを入力し、次に「3」の数字を入力することを決定した場合、ユーザは3未満の数字を入力し続ける限り、ループは進むだろう! –