Basic JavaScript - Global Scope and Functions

Tell us what’s happening:
Describe your issue in detail here.

I’m not sure what I’m doing wrong here. Here are the tasks:

  • 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

Your code so far

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

function fun1() {
  // Assign 5 to oopsGlobal here
  oopGlobal = 5;
}

// Only change code above this line

function fun2() {
  let 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/114.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

You have a typo here

Oh my god thank you! I thought I was going crazy here lol

1 Like

I know that feeling hahaha

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