question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global Scope and Functions

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
wickedkittenzcommented, Nov 25, 2016

copy & paste oopsGlobal from the text below to your variable and it works.

1reaction
earendillocommented, Sep 9, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found