New to JS, please be beautiful.
When creating a Javascript score for playing in a browser canvas, the code below is incremented by 1 for every second. If the value of the variable is 100, how would I go around this function by displaying a window warning when it reaches this value?
Attempts similar to if (score == 100); alert (rating) did not work for me.
Below code will not work in JSFiddle, the output will be displayed on the browser tab.
var start = new Date().getTime(),
score = '0.1';
window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000) ;
if(Math.round(score) == score)
{ score += '.0 Score'; }
document.title = score;
}, 100);
Run codeHide result
source
share