Writing a call in the functional scope


#1

I'm not sure how to write this call that is required for #5. Can anyone help?


#2

You called it correctly but there is a spelling error. The instructions also ask that you eliminate the console.log statement before you call the myApartment function.


#3

Thank you, that cleared it up. The console.log that they are talking about is one that was written in the global scope (outside the function) and I did that before. They were trying to show how if I call something from the function in the global scope, nothing will happen which was true.

Thanks for the help! Sometimes we forget to check little details like that when we are wrapped up in other things. It's the worst!


#4

I think this should get my past Step 5 but it doesn't :frowning:

var laundryRoom = 'Basement';
var mailRoom = 'Room 1A';

function myApartment() {
var mailBoxNumber = 'Box 3';
var laundryRoom = 'In-unit';
console.log('Mail box: ' + mailBoxNumber + ', Laundry:' + laundryRoom);

};

myApartment();
console.log(mailBoxNumber);

Even commenting out the inner (function console) does not work
I keep getting:

Did you write a console.log with the variable mailBoxNumber in it after the myApartment function?

Does not make sense to me
Any help appreciated


#5

Same Here I need help with it has well


#6

I sorted it by searching the forum
The tutorial tool that codeacademy uses seems to be very precise about the order, see below this works:

var laundryRoom = 'Basement';
var mailRoom = 'Room 1A';
var myApartment = function() {
var mailBoxNumber = 'Box 3';
console.log('Mail box: ' + mailBoxNumber + ', Laundry:' + laundryRoom);
};

// console.log(mailBoxNumber);
myApartment();


#7

Yes, this (when also uncommenting the penultimate line, that is) finally also made me pass the exercise - but I think it would be helpful if someone could please explain why the developers apparently preferred this order of statements, which as far as I understand it might also be strange from an educational point of view: to me it seems logical that any variable (be it local or global) as defined in myApartment() is not accessible outside the myApartment() scope when this function has not been called yet...?

Thank you very much in advance.


#8

4) var laundryRoom = 'Basement';
var mailRoom = 'Room 1A';

function myApartment() {
var mailBoxNumber = 'Box 3';
var laundryRoom = 'In-unit';
console.log('Mail box: ' + mailBoxNumber + ', Laundry:' + laundryRoom);
};
console.log(mailBoxNumber); // remove this #5

myApartment();

5) var laundryRoom = 'Basement';

var mailRoom = 'Room 1A';

function myApartment() {
var mailBoxNumber = 'Box 3';
var laundryRoom = 'In-unit';
console.log('Mail box: ' + mailBoxNumber + ', Laundry:' + laundryRoom);
};
myApartment();

o/p : done