Not working Javascript Code for me

Hello, Im trying to understand Javascript via freecodecamp. everything was working fine for me but now I stucked at Global Scope and Functions.

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

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

This code is given :

// Declare the myGlobal variable below this line

function fun1() {
  // Assign 5 to oopsGlobal here

}

// 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);
}

Im doing this :

// Declare your variable here
var myGlobal = 10;

function fun1() {
  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);
}

but its saying that Failed:myGlobal should be declared using the let or const keywords;

I tried to copy solution too but its not working either. what should I do ? (((
Thanks in advance

It looks like some of your double quotes are not the correct type. The correct type is " not “

Also please post your code in a code block so it is in a readable form on the forum.

Instructions below:

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Thank you for ur response, I done it))
the problem was in the first line : // Declare your variable here
var myGlobal = 10;

I was using var instead of let)) nothing more
thanks anyway <3

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