Basic JavaScript - Global Scope and Functions

Tell us what’s happening:
Hi Team, first time I’ve posted here. I’ve done every search, I’ve watched the video (which types var, not const or let, but that difference was clear) and everywhere says the same: define with: const myGlobal = 10; \ but when I type this, along with it’s second oppsGlobal = 5; I received the fail message- myGlobal should be defined.

  • Failed: myGlobal should be defined
  • Failed: myGlobal should have a value of 10
  • Passed: myGlobal should be declared using the let or const keywords
    Failed: oopsGlobal should be a global variable and have a value of 5

I’ve tried const myGlobal = [10]; as well as const myGlobal = “10” (though even I knew that wouldn’t work. I’ve checked w3schools and all resources available here, everyone writes it the same, but it still says it’s not defined. I can’t see what I’m doing wrong. Sorry to trouble all.

Your code so far

// Declare the myGlobal variable below this line
const 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);
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

This can be closed now. Somehow I solved it, but it seems the only thing i changed was i removed the “;”

// Declare the myGlobal variable below this line
const 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);
}

We have blurred this solution so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

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