I made a simple timer in javascript using a for loop, but upon clicking the button to call the function test(), the whole page freezes up so I assume I have an infinite loop somewhere
This is my code:
<html>
<head>
<script>
function test() {
var HowLong = 5;
for (var i=0;i<HowLong;i--) {
document.write(HowLong[i] + "<br>");
}
}
</script>
</head>
<body>
<input type="button" onclick="test()" value="Start Timer">
</body>
</html>
HowLongis a number, but you are trying to use it like an object (HowLong[i]). You probably want to useionly. c) Even if you fix that, you wouldn't actually see the change of each iteration. The execution of the loop is so instantaneous that you will only see the change of the last iteration. I recommend to read a tutorial about basic data types in JavaScript: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…