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 on beta.freecodecamp

See original GitHub issue

Answer is not accepted on the Beta Freecodecamp. “Do not declare oopsGlobal using the var keyword” is the only issue showing up.

Challenge Global Scope and Functions has an issue. User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


// 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);
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
raisedadeadcommented, Jan 27, 2017

Needs a bot more creative solution though, will take a look when I can, but keeping open for others to pitch in.

1reaction
systimoticcommented, Jan 21, 2017

I found the source of the issue! var oopsGlobal; is in the head here. This is now an issue because the head and tail are now included in the tests (https://github.com/freeCodeCamp/freeCodeCamp/issues/10258)

Removing the definition from the head fixes the browser tests, but it breaks the CI tests.

@freeCodeCamp/moderators What would work, is moving var oopsGlobal; to the beginning of the solution, although that seems a bit hacky to me. Should I go through with that?

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 >
Free Code Camp - Basic Javascript Flashcards | Quizlet
We tell JavaScript to create or declare a variable by putting the keyword var ... Variables which are defined outside of a function...
Read more >
Generate Random Whole Numbers within a Range - JavaScript
Freecodecamp Basic JavaScript: Generate Random Whole Numbers within a Range ... declare variables(old way of declaring variables), Function or global scope.
Read more >
define global and local scope? - Codecademy
In the picture below, the scope of the local variable is highlighted blue – it's the function where that var was defined. Any...
Read more >
FreeCodeCamp/HelpBackEnd - Gitter
It would be very bad programming practice to make a variable outside of the scope of a function, that is ONLY used WITHIN...
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