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