Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

697
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda