So, I want to create a timer and this is the code I have so far.
<!DOCTYPE html>
<html>
<head>
<title>WIP</title>
<meta charset="UFT-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function timerCreate(minutes, seconds) {
var i = 0;
var f = 0;
$("#timerText").text((minutes - f) + ":" + (seconds - i));
i++;
do {
interval = setInterval(function() {
$("#timerText").text((minutes - f) + ":" + (seconds - i));
i++;
if (i >= seconds) {
clearInterval(interval);
setTimeout(function() {
$("#timerText").text((minutes - f) + ":" + "0");
}, 1000);
if (minutes > 0) {
f++;
}
}
}, 1000);
} while (!(f = minutes));
}
</script>
</head>
<body onload='timerCreate(5, 4)'>
<div id="timerText">Timer</div>
</body>
</html>
Please run the code to see what it does. I don't understand why it does this. Could anyone help? Also, although I fell like I'll eventually get it, this code seems to me way too all over the place. If you agree, I'd be really grateful if you could link me to some code for a timer. Either way, I'd really like it if you could explain to me what I'm doing wrong.
Thanks so much to anyone who answers. :-)