Javascript: Request a number with prompt, if it is different from 0 duplicate and show alert, if it is equal to 0 avoid loop

0

I put the following code, I only run one round

numero = prompt("Escribe un número") 
var multiplica = numero * 2; 

while (numero != "0") { 
    alert (numero*2);
}
    
asked by Nico Piovano 24.07.2018 в 01:11
source

1 answer

1

You have to put the prompt inside the while:

var numero;

while (numero != "0"){ 
    numero = prompt("Escribe un número") 
    if (numero == 0) {
      alert("Gracias");
    } else {
      var multiplica = numero * 2; 
      alert (numero*2);
    }
}
    
answered by 24.07.2018 в 01:18