Local variable error

Tell us what’s happening:

I use this code and it doesn’t work, could you help me sort it out? It gives me this error message:
" You should add a local “myVar” variable.

Your code so far

function myLocalScope() {
var myVar = 2;


**Challenge:** Local Scope and Functions

Declare a local variable myVar inside myLocalScope and run the tests.

This is assignment:
var x = 1;

This is declaring:
var x;

Which one do you need to do and why is yours wrong?


You’re missing the point of the terminology. The instructions says to declare a variable and he does both (declares and assigns). And if you want to be technical about it, you can delete that line ‘use strict’ and it still works. Try it before you give wrong advice.

The technical reason why it won’t pass is because he’s missing the comment // Only change code below this line and apparently the parser wants this line in it.

Move your declaration AFTER the comment.


Many thanks… it was because I deleted ‘use strict’.