-4

Let me explain. I want that my program do the following:

1º Ask the user to enter a value of time in seconds 2º Start a countdown from the value that the user has finishedand show him 3º when it finishes, it alerts the user that the time has finished.

This is my code so far (I do not know how to do it, I have tried many times), I did it with prompt and alert but maybe using html there is a solution

let counter= prompt("Please, select in how much time (in seconds) do you want me to alert you")

{
    SetTimeOut(() =>
     {
        (console.log("Alert: you have completed your time"), counter) 
     })
}

while (setTimeout>0)
    {
        alert("your time finishes in: "+ counter + "seconds")

    }
  • 1
    JavaScript is case-sensitive. Also, this `while` is blocking the thread and nothing can run because of it – Konrad Oct 22 '22 at 16:44
  • I guess that you are getting downvoted because your question is really basic and you should first learn the basics before asking a question on a website for intermediate/advanced developers – Konrad Oct 22 '22 at 17:02
  • There are thousands of free resources that you can access now without wasting your and others' time on a question which has to be individually answered – Konrad Oct 22 '22 at 17:07
  • 1
    You should first debug your code and then ask a specific question. [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems#25385174) [How to debug small programs?](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) _"StackOverflow is a question-and-answer site for specific questions about actual code; “I wrote some buggy code that I can’t fix” is not a question, it’s a story, and not even an interesting story."_ You didn't even ask a question. – jabaa Oct 22 '22 at 17:11

1 Answers1

1

First of all it's setTimeout not SetTimeOut

JavaScript runs in one thread and things work on callbacks/promises instead of while loops

// get the value
// convert it to number using `+` operator
// multiply by 1000 to get milliseconds
const counter = +prompt("Please, select in how much time (in seconds) do you want me to alert you") * 1000

// set timeout to run after `counter` milliseconds
setTimeout(() => {
  // log alert
  console.log("Alert: you have completed your time", counter)
}, counter)
Konrad
  • 21,590
  • 4
  • 28
  • 64