Basic JavaScript: Local Scope and Functions (You should add a local myVar variable error)

Tell us what’s happening:

I would appreciate any help, because I didn’t find any solution for this problem. As I declare a local variable inside of the myLocalScope function , i recieve the next error message in the test window :

// running tests
You should add a local myVar variable. 
// tests completed 

//console output 
SyntaxError: invalid regular expression flag s

I’ve tried to declare myVar variable in different ways, like

var myVar = “string”;


var myVar;
myVar = /* any type of value */

but nothing seems to work. I’ve done the code reset multiple times, reloaded my browser, still the same issue.

Thanks in advance for your help.

Your code so far

function myLocalScope() {
'use strict';

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Local Scope and Functions

Link to the challenge:

Hi @ryodenshi. Welcome to FCC. It is intentional for the console to display an error message. It is supposed to help you understand the concept of local scope. If you submit, the test will pass even with the error message in the console.

Thank you for your reply @nibble. I understand that console is supposed to display an error (as it was written in the “Note” section of the task), but my main concern is about why my code still can’t pass all tests - as I’ve mentioned before, tests show that I haven’t declared the local variable inside the given function, even if I had done quite the opposite (see my code). I am afraid there could be some kind of a bug.

Because you where asked specificly to
Declare a local variable myVar inside myLocalScope and run the tests.

var myVar = 5;

Where does the is equal to 5 come from?
I think you misreaded the assigment :3

When i submit your code as it is, the test passes. The problem could be browser related perhaps. Try submitting using a different browser.

1 Like

You were right, that happened to be a browser related problem. Tests didn’t work for Firefox neither for Firefox Developer Edition or Microsoft Edge, but worked well for Google Chrome. Thanks for pointing out where the problem could be. Good luck on your coding adventures!


Yes, the problem is in browser. The challenge does not want to pass with Firefox I recommend using google chrome for learning.

1 Like