I'm not sure why the user would want to see multiple alerts, but try:
let number = prompt("Write a number");
for (let i = 1; i <= number; i++) {
alert(i);
}
You would still need to check that number is a valid number before running the for(..) loop. Also note that some browsers allow users the choice of hiding multiple alerts.
0
Itamar
On
This snippet will trigger X alerts from a prompt input
let number = prompt("Write a number");
for (var i = 0; i< parseInt(number); i++){
alert('hey '+i+1)
}
0
Jean-Louis Larrieu
On
let number = prompt("Write a number");
for (var i = 0; i< parseInt(number); i++){
alert('hey '+i+1)
}
0
Jean-Louis Larrieu
On
I'd only like to add that you need to add the Number function in the alert prompt or else it will consider it like a string.
let number = prompt("Write a number");
for (let i = 0; i< parseInt(number); i++){
alert('hey ' + Number(i + 1));
}
I'm not sure why the user would want to see multiple alerts, but try:
You would still need to check that
numberis a valid number before running thefor(..)loop. Also note that some browsers allow users the choice of hiding multiple alerts.