Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichal Janek
Front End Web Development Techdegree Graduate 30,654 PointsWhy Lilah 3rd time?
I am sorry I tried reviewing the video several times but I just cannot figure out, why there is a 3rd Lilah alert at 1:30 min of the Scope video. Maybe I am too tired at this point but I do not really see that part which calls for third Lilah Alert.
Was it because first calling greeting(); created "3" variable with name person so our second calling of that function makes it read the first calling?
2 Answers
Justin Olson
13,792 PointsIt's easy to miss how this works, especially if you are tired. ;)
Basically, there are three parts being called.
greeting(); This initiates the greeting() function, which asks to alert(person); which is Lilah
alert(person); Since the greeting() function just ran, next is this, asking to alert the variable, person. As this is outside the function, it stands alone, and will come back with George.
greeting(); Lastly, the greeting() function is called one more time. Like before, it runs the same code. As the variable for person INSIDE the function is Lilah, Lilah will be the name called.
These will fire in this order, which is why you will see Lilah, George, then Lilah again. Hope this helps out. :)
Edit: forgot to put this an an answer. :)
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points...it was so obvious. Thank you. Should get some rest for a while :D
Amber Touch
2,339 PointsHaha this is far from obvious. I still don't get it myself.
Justin Olson
13,792 PointsJustin Olson
13,792 PointsIt's easy to miss how this works, especially if you are tired. ;)
Basically, there are three parts being called.
greeting(); This initiates the greeting() function, which asks to alert(person); which is Lilah
alert(person); Since the greeting() function just ran, next is this, asking to alert the variable, person. As this is outside the function, it stands alone, and will come back with George.
greeting(); Lastly, the greeting() function is called one more time. Like before, it runs the same code. As the variable for person INSIDE the function is Lilah, Lilah will be the name called.
These will fire in this order, which is why you will see Lilah, George, then Lilah again. Hope this helps out. :)