Login | Register | FAQ
Anonymous

Lesson 17 "greeting undefined"

+ Post a reply

Page 1 of 1


Lesson 17 "greeting undefined"

by tcwoods1 » Sat May 11, 2013 8:35 pm

I tried the example in lesson 17 and the interval timer is not clearing. I used IE9's F12 debugger and it says "greeting" is undefined for the stopTimer function. Can someone look at code and tell me what's wrong.

<!DOCTYPE html>
<html>
<head>
<title>my test</title>
</head>
<body>
<h1>My TEST</h1>

<script type="text/javascript">
function myHello()
{
alert("Hello");
}

function timeGreeting()
{
var greeting = setInterval(myHello,5000);
}
function stopTimer()
{
alert("this works");
clearInterval(greeting);
}
timeGreeting();
</script>

<input type="button" value="STOP IT" onclick="stopTimer()" />
</body>
</html>
User avatar

tcwoods1

  • Posts: 2
  • Joined: Thu May 02, 2013 11:42 pm

Re: Lesson 17 "greeting undefined"

by tcwoods1 » Sat May 11, 2013 8:51 pm

I found the problem
I forgot to set "greeting" as a global variable and remove the local setting.
User avatar

tcwoods1

  • Posts: 2
  • Joined: Thu May 02, 2013 11:42 pm

Re: Lesson 17 "greeting undefined"

by XainPro » Wed May 15, 2013 7:50 am

lol good
self learning = best learning
User avatar

XainPro

  • Posts: 2401
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1