Block Scope II


#1

I have no idea what’s wrong here :frowning:

https://www.codecademy.com/courses/learn-javascript-scope/lessons/scope/exercises/block-scope-ii?action=resume_content_item&course_redirect=introduction-to-javascript


#2

the exercise url is nice for the helping side to gain quick access to the lesson, however, it will load my own code and not yours (it checks which user is signed in)

what code do you have? What is not working as expected?


#3

I created a variable , just like the instructions ask but its wrong?

const visibleLightWaves = () => {
let lightWaves = ;
console.log(lightWaves);
};

visibleLightWaves();
console.log(lightWaves);


#4

this is the starting code:

const visibleLightWaves = () => {
  let lightWaves = 'Moonlight';
  console.log(lightWaves);
};

visibleLightWaves();
console.log(lightWaves);

Why doesn’t your lightWaves variable have a value? Seems you removed the wrong thing, if we run the default code we get:

/home/ccuser/workspace/javascript_101_Unit_3b/light.js:7
console.log(lightWaves);

the error is caused by line 7, given lightWaves only exist within the function, so you should remove the line which attempts to log a value which is not in its scope, seems you removed the wrong thing. Why would you want to change let lightWaves = 'Moonlight'; to let lightWaves = ;?


#5

There are the instrutions:
1.

Remove the statement that erroneously logs the value of the lightWaves variable to the console outside of the function block.
2.

Let’s continue by adding another variable to the visibleLightWaves() function. Beneath the lightWaves variable, using let, add a variable region and set it equal to ‘The Arctic’.


#6

After I removed it, it seems to check correct in the instructions. idk T^T


#7

what is it referring to? Do you also understand why?


#8

Remove the statement that erroneously logs the value of the lightWaves variable


#9

const visibleLightWaves = () => {
let lightWaves = ;
let region = ‘The Arctic’;
console.log(lightWaves);
};

visibleLightWaves();
console.log(lightWaves);


#10

you can declare empty variable in JS:

let lightWaves;

or give it a value:

let lightWaves = 'Moonlight';

what you are currently doing is not valid

Why haven’t you removed the statement yet that caused the error?

lightWaves only exist within the function (scope), so you should remove the console.log() which attempts to log a variable which is not in its scope


#11

The erorr is created because of the instructions.
Mind you I am not asking about the erorr but about why creating the variable region = ‘The Arctic’; seems to be incorrect.


#12

If there is an error in your program, it will never approve the creation of the region variable


#13

Perhaps this needs to be debugged then.
Thank you for the help:)


#14

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