<html>
<head>
<script type="text/javascript">
function loop(a)
{
for (i = a; i <= 5; i++)
{
document.write("The number is " + i);
document.write("<br />");
}
document.write("<input type=\"button\" onclick=\"loop(-1)\" value=\"click\" />");
}
</script>
</head>
<body onload="loop(0)">
</body>
</html>
I just started learning Javascript, and I don't understand why this isn't working properly. It displays numbers from 0 to 5 when the page loads and a button that when clicked, should add a -1 to the list. However, when the button is clicked, the -1 isn't added to the list. Could anyone explain to me why this happens?


Sign In
Create Account

Back to top









