As a new software engineering student, I am facing a challenge that I am struggling to overcome. I am currently working on developing a basic rhythm game similar to Guitar Hero using HTML, CSS, and JavaScript.
I have successfully implemented an elapsedTime function that starts a timer as soon as the start button is pressed. However, I am now stuck on how to create a function that utilizes this elapsed time to drop notes based on integers/floats stored in an array. Essentially, I need to compare the numbers in the array to the current elapsed time and determine when it is the appropriate moment to drop a note. Any suggestions or explanations on how to tackle this issue would be highly appreciated. Thank you in advance!
let elapsedTime = 0;
let counter = 0;
function increaseCounter() {
if (counter >= 10) {
clearInterval(intervalId); // Stop the interval when the counter reaches 10
console.log("Interval stopped.");
return;
} else {
counter++;
console.log(`The counter is ${counter}`);
}
}
const intervalId = setInterval(increaseCounter, 428.571);