Question on Javascript Scope Exercise: Apartment

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-javascript/lessons/scope/exercises/functional-scope?action=lesson_resume&link_content_target=interstitial_lesson

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Hi, sorry if this seems like a super basic question but I was wondering if anyone could explain this code to me. I posted the ‘hint’ offered by Codecademy in the exercise.

What I don’t understand is, why is mailBoxNumber a variable but laundryRoom isn’t? Also, what is the console.log(’ … ') for?

Thanks in advance!

```

function myApartment() {
var mailBoxNumber = ‘Box 3’;
laundryRoom = ‘In-unit’;
console.log(’ … ');
}

myApartment();

<do not remove the three backticks above>

So there is one big difference between these two lines of code. The key word var declares variables. So when it is put before mailBoxNumber that declares it as a variable.

Regarding console.log check out this thread. https://www.codecademy.com/en/forum_questions/5479b60480ff33483b0029cc

Thank you for the explanation!

Both of them are variables but this is the first time we’re using ‘mailBoxNumber’ so we have to declare it with ‘var’. The reference to laundryRoom is using the same laundryRoom variable that we declared above.

In step 4 you’re asked to log the ‘mailBoxNumber’ outside the function. What does it print out and why?

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