Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Lesson 8 level 8( scope of variables)

1. Create a global variable named a using let keyword and give value "Hello" to it.
2. Then, create a local variable named b using let keyword within the function body of greeting() function and give value "Studytonight" to it.
3. Click on the Run and you should get an exception in the output.

/ Add global variable a here*/
let a = "Hello";

function greeting() {
/* Add the local variable here
/
let b = "Studytonight";

console.log(`${a} ${b}`);
}
greeting();
console.log(a + b);

The compiler is showing try again. Please someone help me to find the error.
by

6 Answers

iamabhishek
Try now, it should work.
Shivanitgxoe
Nope its not working!!!
durgaprasadnnb8y
Not working
durgaprasadnnb8y
/ Add global variable a here*/
let a = "Hello";
function greeting() {
/* Add the local variable here*/
let b= "Studytonight";
console.log(`${a} ${b}`);
}
greeting();
console.log(a + b);
when i click on submit it showing:
*We cannot see anything in the Output panel. Did you Run/Execute the code?

please help me
niyitanga
The error is on variable b in this statement console.log(a + b); because is local variable can not be accessed out of function.
durgaprasadnnb8y
Thank you

Login / Signup to Answer the Question.