set timer 1

set timer

const prompt = require('prompt-sync')();
//You gotta download prompt-sync by doing npm i prompt-sync
var time = prompt("Give time in seconds: ")
time = parseInt(time)
setInterval(function(){
    console.log(time)
    if(time = 0){
        console.log("Time over")
    }
    else{
    time = time - 1}
}, 1000);

Here is what the above code is Doing:
1. It’s asking for the time in seconds.
2. It’s converting the time into an integer.
3. It’s setting an interval of 1 second.
4. It’s printing the time.
5. If the time is 0, it’s printing “Time over”.
6. If the time is not 0, it’s subtracting 1 from the time.

Similar Posts