Hi,
I'm working on a tiny countdown timer JS project. I found that little piece of code on Internet, and it works well.
let count = 60;
const timer = setInterval(function() {
count--;
console.log(count);
if (count === 0) {
clearInterval(timer);
console.log("Time's up!");
}
}, 1000);
Now I don't understand how to add a prompt so the player can type a string of numbers to stop it or even having JS to setup a code randomly. I considered implementing some RNG/Math random feature, but I have no idea how to build and proceed with it. I'm absolutely puzzled and can't find a clear example of the Internet. Reading classes on the JS Institute does not help me develop something at the most fundamental level.
I am looking for a code at the very beginner level, very sober and simple (Functions, Loops but no template strings). Please, any ideas?
I'm working on a tiny countdown timer JS project. I found that little piece of code on Internet, and it works well.
let count = 60;
const timer = setInterval(function() {
count--;
console.log(count);
if (count === 0) {
clearInterval(timer);
console.log("Time's up!");
}
}, 1000);
Now I don't understand how to add a prompt so the player can type a string of numbers to stop it or even having JS to setup a code randomly. I considered implementing some RNG/Math random feature, but I have no idea how to build and proceed with it. I'm absolutely puzzled and can't find a clear example of the Internet. Reading classes on the JS Institute does not help me develop something at the most fundamental level.
I am looking for a code at the very beginner level, very sober and simple (Functions, Loops but no template strings). Please, any ideas?
Last edited: