0

I've been messing around with objects in Javascript and I've come across a problem. Basically I'm trying to print certain properties from objects I've created and it's not working properly.

Here's the code:

function Hotel(name, rooms, booked) {

this.name = name;
this.rooms = rooms;
this.booked = booked;

var CanadaHotel = new Hotel("CanadaIn", 50, 10);
var AmericanHotel = new Hotel("AmericanIn", 60, 3);

document.write(CanadaHotel.rooms);
document.write(AmericanHotel.booked);

None of the properties are being displayed and I don't know why.. any help is greatly appreciated.

Thank you

1 Answer 1

2
SyntaxError: missing } after function body

Fixed

function Hotel(name, rooms, booked) {

this.name = name;
this.rooms = rooms;
this.booked = booked;

}

var CanadaHotel = new Hotel("CanadaIn", 50, 10);
var AmericanHotel = new Hotel("AmericanIn", 60, 3);

console.log(CanadaHotel.rooms);
console.log(AmericanHotel.booked);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, what a stupid mistake I have to be more careful. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.