Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions

Tell us what’s happening:

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.

Challenge: Global Scope and Functions

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions

Hello Abhina.

You have not asked a question. What do you want help with, specifically?

You have a syntax error as you are not closing the function. consider writing code with proper indentation and also you can’t access the local variables outside the code. Consider going throught the tutorial once for a quick refresher so here are some modifications.

// 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 = "";//var output is a local variable consider it defining as a global
if (typeof myGlobal != "undefined") {
  output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
  output += " oopsGlobal: " + oopsGlobal;
}
}//this was missing the closing brace for function
console.log(output);