Javascript Code not running

0 Robert Summers · October 9, 2014
<!DOCTYPE html>

<html>

<head>
</head>

<body>

<script type="text/javascript">

var i = 1;

while(i<10){
function printStuff(){
document.write("Hey " + i + "<br/>");
}
setInterval("printStuff", 2000); 
i++;
}


</script>

</body>

</html>

Post a Reply

Replies

Oldest  Newest  Rating
0 Robert Summers · October 10, 2014
Okay so I have made the change but it keeps print


Hey 10
Hey 10
Hey 10
Hey 10

Instead of

Hey 1
Hey 2
Hey 3
Hey 4
Hey 5
Hey 6
etc

Please help and thanks in return
0 Robin Larsson · October 10, 2014
No, the quotes it's not the problem, it works anyway. It's the parenthesis, without them you don't call the function. :)
0 Robert Summers · October 9, 2014
Okay, cause I was following one of buckys tutorials and he never used parenthesis but I thought something was wrong with his code. Thank you for your help. :)
0 Robin Larsson · October 9, 2014
Dont forget the "()" when you calling a function. In setInterval you forgot them, and function is not called. :)


while(i<10){
function printStuff(){
document.write("Hey " + i + "<br/>");
}
setInterval("printStuff()", 2000);
i++;
}


Should be like this :)
  • 1

Javascript

107,301 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators