0

I've looked into it and cannot figure out why this program is throwing an error in the console.

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('Laundry: ' + laundryRoom + ', Mail: ' + mailRoom);
console.log(myApartment());

Output:

Laundry: Basement, Mail: Room 1A
Mail box: Box 3, Laundry:In-unit
undefined

Everything seems fine until this last "undefined".

Any insight would be appreciated.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
v. carey
  • 1
  • 1
  • 2

2 Answers2

1

myApartment() doesn't return anything explicitly, so it implicitly returns undefined. Just call myApartment() directly, not console.log(myApartment());.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Ramanlfc
  • 8,283
  • 1
  • 18
  • 24
0

myApartment is a function

The return value of a function is undefined.

Please put a return in your function.

Robert I
  • 1,509
  • 2
  • 11
  • 18