Basic JavaScript - Global Scope and Functions

I am trying to pass this level and have read all of the forums that others have posted and watched the videos but cannot get it right,

The only this that will not get checked off is “oppsGlobal should be a variable and have a value of 5”

// Declare the myGlobal variable below this line
let myGlobal = 10;

function fun1(oppsGlobal) {
  // Assign 5 to oopsGlobal Here
oppsGlobal=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/106.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

you are not supposed to change the parameters of the fun1 function…

I changed it now it says that “myGlobal should be defined”, “myGlobal should have a value of 10”, and “oppGlobal should be a global variable and have a value of 5”

// Declare the myGlobal variable below this line
let myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oppsGlobal = 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);
}

check the spelling. Is it opps or oops?

Yep that fixed it. I had been stuck on that all day thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.