Where is the failure?


Joined
Nov 23, 2019
Messages
67
Reaction score
1
JS code is given below.


function Hotel(name, rooms, booked) {
this.name = name;
this.rooms = rooms;
this.booked = booked;
this.checkp = function() {
return this.rooms - this.booked;
};
}
var quayHotel = new Hotel('Quay', 40, 25);
var parkHotel = new Hotel('Park', 120, 77);

var details1 = quayHotel.name + ' rooms: ';
details1 +=quayHotel.checkp();
var elHotel1 = document.getElementById('hotel1');
elHotel1.textContent = details1;

var details2 = parkHotel.name + 'rooms: ';
details2 += parkHotel.checkp();
var elHotel2 = document.getElementById('hotel2');
elHotel2.textContent = details2;

many thanks for your response.
 
Ad

Advertisements

Joined
Nov 23, 2019
Messages
67
Reaction score
1
note: in mozilla browser's console: it gives me an error and says : "TypeError: elHotel1 is null "

but why?
 
Joined
Nov 27, 2019
Messages
163
Reaction score
24
Maybe because your posted code does not contain the DIVs where your posting your results?
You need something like this in the body:
Code:
<div id ='hotel1'></div>
<div id ='hotel2'></div>
JS and HTML work together and both must be coded/posted to make sense of it.
 
Ad

Advertisements

Joined
Nov 23, 2019
Messages
67
Reaction score
1
resolved

many thanks .

(meanwhile, may I ask whether we could use html's markup in any part of JS file.)

(as example : we have such samples like this:

(but we only post here a piece of sample. not whole of its)


var msg = '<h2>length</h2><p> ' +saying.length+ '</p>'
msg += '<h2>uppercase</ h2><p>' + saying .toUpperCase() + '</ p>'


for instance,I was thinking that '<h2> length</h2><p> '
was the value of msg variable, and it progress via + operator and so on. but it does not seem wholly logical. (I (must) have (had) absence at somewhere in my this opinion)
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top