Basic JavaScript - Global Scope and Functions

Tell us what’s happening:
Hello everyone! I am super new to coding so I have no idea what I am doing wrong here. I declared “myGlobal” with using “var” and assigned “oppsGlobal” a value of 5 within the function “fun1()”, but idk why the code is not working.

  **Your code so far**
// Declare the myGlobal variable below this line
let myGlobal = 10;
var oppsGlobal = 5;

function fun1() {
 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;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15

Challenge: Basic JavaScript - Global Scope and Functions

Link to the challenge:

This is a typo. It’s “oops” not “opps”.

Also, do not declare this variable at the top outside of the function. That’s the point of this challenge, to show you what happens when you accidentally create a global variable inside of a function.

name variable error
it’s oopsGlobal not oppsGlobal

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