Елена Ом Елена Ом - 11 days ago 5
Javascript Question

How to fill empty array with "for loop" and "prompt(' ')" in javascript

I have written:



var arr = [];
for (i = 0; i < 5; i++) {
var name = prompt('please, enter your name');
arr.push(name);
}

console.log(arr);





But it is does not work. It asks me only once, but I need to make arrey with five names. Please help me to find my mistake.

Answer

It worked for me. Are you using Google Chrome to test. Maybe something for above it is interrupting. Try it on a new Javascript File. If you're using Chrome to test what is the log saying Ctrl + Shift + J let me know.

Thanks :)

Comments