2. Functional Scope: Printing 'undefined'


#1


https://www.codecademy.com/courses/learn-javascript/lessons/scope/exercises/functional-scope?action=lesson_resume&link_content_target=interstitial_lesson


I dont have any error messages. I've entered all the code in correctly and the program is letting me move on to the next lesson. But for some reason the word "undefined" printed at the bottom of my output.
Does anyone know why the program is adding text at the end of my output?


var laundryRoom = "basement";
var mailRoom = "Room 1A";

function myApartment(){
  var mailBoxNumber = "Box 3";
  var laundryRoom = "In-unit";
  console.log('\nMail box: '+ mailBoxNumber + '\nLaundry: '+ laundryRoom);
}

console.log('Laundry: '+ laundryRoom + '\nMail: ' + mailRoom);
console.log(myApartment());


#2

console.log(myApartment());

It's because of this. There's no need for a console.log around calling a function.

So you call your function like this myFunction()
One console.log, one function call.


#3

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