I am new to javascript and I want to create a program that loops a prompt(input) but to a limit specifically four times and saves each looped prompt to an array. This is my code
const fruits = [];
var ask = prompt('Enter a fruit');
for(let num = 0; num < 5; num++){
fruits.push(ask); } console.log(fruits);
const fruits = [];
var ask = prompt('Enter a fruit');
for(let num = 0; num < 5; num++){
fruits.push(ask);
}
console.log(fruits);
But this is the result [ "Banana", "Banana", "Banana", "Banana", "Banana" ]
It only asks for the input once and saves it in the array five times, any ideas?
promptcall inside the loop.