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 trialTrevor Johnson
14,427 PointsJS Help With Local Scope & Functions
I am trying to do this code challenge on Free Code Camp, and it seems to me like I am doing everything right but it isn't working. Any help is appreciated
Here are the directions:
Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor.
function myLocalScope() {
var myVar = 'use strict';
console.log(myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
// Now remove the console log line to pass the test
1 Answer
andren
28,558 PointsIf you removed the second console
call then you don't seem to be doing anything wrong. I decided to try the test myself and using your code with the console
call removed:
function myLocalScope() {
var myVar = 'use strict';
console.log(myVar);
}
myLocalScope();
It did seem to pass the test fine, maybe it was just a temporary bug?
Trevor Johnson
14,427 PointsIt seemed to be a bug. It let me pass this time.
Trevor Johnson
14,427 PointsTrevor Johnson
14,427 PointsI get that it is trying to show me that a local variable can't be called outside of a function. Nothing changes though when I remove the console.log(myVar) which tries to call the local variable that doesn't exist globally.