Propblems with output console

Propblems with output console
0.0 0

#1

Hi guys.
I have some problems with my output console when I do JavaScript challenges. I cant see my output in this console even whtn I write "console.log". I can see only condition of my tasks which I have to do. At the same time I can see result in dev tools console. I use Chrome browser. Heres my code:

function checkScope() {
“use strict”;
let i = “function scope”;
if (true) {
i = “block scope”;
console.log("Block scope i is: ", i);
}
console.log("Function scope i is: ", i);
return i;
}

And here`s my output:

// running test
checkScope() should return “function scope”
// tests completed

How can I fix it?
thank`s a lot)


#2

Hi @weregon7,

Try to put false rather than true so, it will be like that:

if(false){
  i= "block scope"
console.log("Block scope i is: ",i);
}

Regards,
Ali Mosaad


#3

Thanks :grinning:
But I am wondering why I can`t see anything in console but condition of running test even if I write “console.log” in my code. Although I can see output in Dev tools console )


#4

Similar kind of issue is already reported in github.


They are working on this issue. For now we have to use the browser console.


#5

Thanks a lot. I thought maybe I have some browser problems or something like that)


#6

Hi @weregon7,

I will explain to you:

let’s move step by step,

First step: let i = “function scope”; // Thats mean you create variable with string "function scope", so, because you write string so it is **boolean true**

Second step: if (true) { i = “block scope”; console.log("Block scope i is: ", i); } //In this step the **if condition is true** and the value of *i* variable is *true* also, so, it will get inside if condition.
Note: The problem here is when getting inside if condition the variable i changed to “Block Scope” and printing as will.

Third step: console.log("Function scope i is: ", i); return i; \\The variable *i* now has value of "block scope", so, when return *i* it return "block scope" because it's stored from condition

Hope this help you, good luck my friend and have a happy coding.

Regards,
Ali Mosaad