Basic JavaScript - Global Scope and Functions

Tell us what’s happening:
Am I doing anything wrong with this code?

  **Your code so far**
// Declare your variable here
var myGlobal=10;
oopsGlobal=5;
function fun1(oopsGlobal) {
  // Assign 5 to oopsGlobal Here
oopsGlobal;  
}
// 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/105.0.0.0 Safari/537.36 Edg/105.0.1343.27

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

Instructions:

Inside function fun1 , assign 5 to oopsGlobal without using the var , let or const keywords.

Where did you assign 5 to oopsGlobal?

Instructions:

Using let or const , declare a global variable named myGlobal outside of any function. Initialize it with a value of 10 .

What key word did you use to delcare the global variable myGlobal?

1 Like

Please clarify your question/concern.
Are you just asking for a code review or are you trying to fix a bug (or other)?

myGlobal should be declared using the let or const keywords
This is the thing I need to have checked.

That is one issue. You did not answer my first question.

“var” is the variable for ‘myGlobal’

Thank you for the info.