Freecodecamp: Waypoint: Local Scope and Functions

Created on 30 Dec 2015  Â·  15Comments  Â·  Source: freeCodeCamp/freeCodeCamp

Challenge Waypoint: Local Scope and Functions has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36.

The test asks you to remove the second console.log() to pass. When you remove the second console.log() it still fails. You have to remove both console.log() calls to pass(including the one inside myFunction().)

Reproducible every time by removing the console.log() outside of myFunction(), as asked by test. I'm assuming this is a bug in the test and not the text as there's no reason to remove the console.log() call within myFunction().

Most helpful comment

If you've made it to this page for help, then refresh the code page before trying the above solutions.

All 15 comments

This issues with this are twofold. First, the instructions are asking you to add a variable named myVar inside the function, but the tests aren't testing for that. If you don't add the variable the console.log inside the function will fail because the variable does not exist, causing the test to fail (even when you've removed the second console.log. We should probably add a first test that checks to make sure the user has created the variable.

Secondly, the test is checking for there to only be one instance of the string "console.log" in the editor window, but if you don't remove the comment there will be two instances of that string even once the second console.log has been removed.

This can be rectified by replacing the existing test with the following test

assert(typeof myVar === 'undefined', 'message: No global <code>myVar</code>');EOL
assert(/var myVar/.test(code), 'message: Add a local <code>myVar</code>');

But if the camper mistakenly creates a global variable and runs the test, then subsequent tests will fail unless the browser is refreshed.

And currently the waypoint can be passed by removing the comment that says to remove the console.log message

@ltegman Removing the comment worked for the time being. OCD attacked.

I have to remove the comment for the test to pass.

If you've made it to this page for help, then refresh the code page before trying the above solutions.

Thanks niallmurphy-ie
Had me scratching my head...

Thank you niallmurphy-ie. You saved my life. (Well at least, some minutes of it).

@niallmurphy-ie @jegger79 exactly! so strange :) thanks for advice

JavaScript does not only confuse the students but the instructors also.
I came across a few JS tests on Codecademy that just wouldn't function like they said.
you just had to hack to get passed.

Refreshing the page does the trick.

I ran in to this issue, and refreshing the page didn't solve it.

Update: The error is that you have to read the commented code to see to remove console.log. You should make a note on the left side to delete console.log or else more people will have the same problem I did.

Thank you @niallmurphy-ie

Neither removing the console.logs nor refreshing the page worked...

@anastasi5 I suggest you please verify your code in <strong><code>FreeCodeCamp/HelpJavaScript</code></strong> chat room.

function myLocalScope() {
var myVar = 5;
console.log(myVar);
}

// Run and check the console
// myVar is not defined outside of myLocalScope

......MORE LIKE THIS
// Now remove the console log line to pass the test

Was this page helpful?
0 / 5 - 0 ratings