Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

699
Vistas
Why is my 'if' statement not creating the alert?

let input = prompt('What would you like to do: (New, List, Delete, Quit)');

while (input === "New") {
    const newToDo = prompt("What would you like to 'ADD' to the list?");
} if (newToDo !== undefined) {
    alert(`${newToDo} added to the list`);
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I'm not going to explicitly write the code here as that would be a lost opportunity for learning. However, here are some starting points that would benefit you:

  1. You shouldn't be using const for a variable whose value is expected to change.
  2. As mentioned in the comment, your variable is out of scope meaning it's unrecognizable outside the while loop. In order to resolve that, declare the variable prior to the loop.
about 4 years ago · Juan Pablo Isaza Denunciar

0

Initialize newToDo in top they it will available all over the scope

let newToDo;
while (input === "New") {
newToDo = prompt("What would you like to 'ADD' to the list?");
}
if (newToDo !== undefined)
{
alert(`${newToDo} added to the list`);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda