Code not working on other editor/console?

Tell us what’s happening:
I’ve passed the challenge and output in the console was:
myGlobal: 10 oopsGlobal: 5

But when I tried the same code on the editor for other challenges or other online JS editor, there was nothing on the output. May I know why? Does this specific challenge has some hidden settings?

  **Your code so far**

var myGlobal = 10

function fun1() {

oopsGlobal = 5
}

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/92.0.4515.159 Safari/537.36 Edg/92.0.902.78

Challenge: Global Scope and Functions

Link to the challenge:

Right, the function calls to fun1() and fun2() are hidden from you.

If I want the same output to be displayed on other platform other than this specific challenge, can I just call the fun1() & fun2() manually?

Yes, I believe that would be the case.

Too bad it still doesn’t work :frowning:

Taking your code up top and appending fun1(); and fun2(); to the end like this:

var myGlobal = 10

function fun1() {

oopsGlobal = 5
}

function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
  output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
  output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

fun1();
fun2();

when run in my browser console outputs the following

myGlobal: 10 oopsGlobal: 5

image

1 Like

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