Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

696
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!