I have the following code but it doesn't seem to work. I want to log to the console "dark-green", have it wait a couple milliseconds, then log "light-green", all WITHOUT using setInterval or setTimeout. Is this possible with javascript?
function logGreen() {
console.log("dark-green");
wait(200);
console.log("light-green");
}
function wait(ms) {
var time = new Date();
var milliseconds = time.getMilliseconds();
var startTime = milliseconds;
var currentTime = milliseconds;
while(currentTime - startTime < ms) {
currentTime = milliseconds;
}
}
The problem I am running into is that the the loop breaks the browser so to speak, and I'm not sure how to fix this. Is there a way to do this with a for loop?