Global Scope and Functions
See original GitHub issueI have problem with last test in this challenge: Using var, declare a global variable myGlobal outside of any function. Initialize it with a value of 10. Inside function fun1, assign 5 to oopsGlobal without using the var keyword.
I have done everything like this:
// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal=5;
}
// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
and everything is ok till this point:
Do not declare oopsGlobal using the var keyword
#### Challenge Name
https://www.freecodecamp.com/en/challenges/basic-javascript/global-scope-and-functions
Issue Description
Browser Information
mozilla firefox 44.0.2, safari
- Operating System: Vista
- Mobile, Desktop, or Tablet: iphone 5s
Issue Analytics
- State:
- Created 7 years ago
- Comments:11
Top Results From Across the Web
freeCodeCamp Challenge Guide: Global Scope and Functions
Global Scope and Functions Hints Hint 1 The scope of a variable is its visibility; where in the code is the function available?...
Read more >Global Scope and Functions - CodeChallenge - GitHub
In JavaScript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope. This means,...
Read more >JavaScript Scope - W3Schools
Variables declared Globally (outside any function) have Global Scope. Global variables can be accessed from anywhere in a JavaScript program. Variables declared ...
Read more >Controlling Execution Contexts with Javascript Global Scope ...
The Javascript global scope is the context where everything in a Javascript program executes by default. This scope includes all variables, ...
Read more >JavaScript Variable Scope (with Examples) - Programiz
A variable declared at the top of a program or outside of a function is considered a global scope variable. Let's see an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
copy & paste oopsGlobal from the text below to your variable and it works.
I have the same issue (Win10, chrome):
// Declare your variable here
var myGlobal = 10; function fun1() { // Assign 5 to oopsGlobal Here oopsGlobal = 5; }
// Only change code above this line function fun2() { var output = “”; if (typeof myGlobal != “undefined”) { output += "myGlobal: " + myGlobal; } if (typeof oopsGlobal != “undefined”) { output += " oopsGlobal: " + oopsGlobal; } console.log(output); }
when I run the code I have “Do not declare oopsGlobal using the var keyword.” not marked.