Scope and Function

Tell us what’s happening:
What am I doing wrong here?

Your code so far


function myLocalScope() {
'use strict';

// Only change code below this line
function myLocalScope() {
var myVar = 5;
console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
// console.log(myVar);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Local Scope and Functions

Link to the challenge:

I believe that you want this to not be commented out.

I tried that and it still is not working…

You’re defining this function…
remove this line and it should pass the tests

What is your current full code?

I had an extra line of

function myLocalScope() {

which was throwing it off so I deleted it and it passed.

function myLocalScope() {
  'use strict';

  // Only change code below this line
  var myVar = 5;
  console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).