Where is the failure?

Joined
Nov 23, 2019
Messages
70
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.
 
Joined
Nov 23, 2019
Messages
70
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
28
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.
 
Joined
Nov 23, 2019
Messages
70
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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,836
Latest member
BuyBlissBitesCBD

Latest Threads

Top