Do not know how to fix the code

I am struggling with this error: myGlobal should be declared using the let or const keywords.
but I do not know how to fix the code . Can you help me??

Your code so far


// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
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);
}
fun1();
fun2();
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Global Scope and Functions

Link to the challenge:

:thinking: I am really struggling so much! (so can you help me?)

And I tried using the let not the var but I got more error! :face_exhaling: I can’t solve this challenge!!!

(Of course, without our help guys )…

And even though, I tried to use the const keyword I gave much more errors so I failed. :face_exhaling: I really need to find the bug in my code!!!

Your functions don’t have a return statement. They are not returning anything at the moment.

but @Slimattcode , It said: Inside function fun1 , assign 5 to oopsGlobal without using the let or const keywords.

Hey.
Here’s what the challenge asks:

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

So the problem you have to fix, is right here:

Hope this helps.

ah right @Slimattcode !
thanks for the reply.

1 Like

and thank you @isimeri to!

woohoo! I just passed It! thank you for the reply
@isimeri !

and @Slimattcode , I did not mean that you are wrong , I meant thank you were right to so thank you @Slimattcode I just passed It with your answer to!

Glad it worked out well :smile:
Keep pushing!

oh of course @isimeri! I love to code so of course.

:grin:, glad we could help. Good luck.

and I love to learn computer science (cs) .

oh well as I said to @isimeri , I love to learn computer science (cs)

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