where is the failure?

Discussion in 'Javascript' started by independent, Nov 30, 2019.

  1. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    14
    Likes Received:
    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.
     
    independent, Nov 30, 2019
    #1
    1. Advertisements

  2. independent

    independent

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

    but why?
     
    independent, Nov 30, 2019
    #2
    1. Advertisements

  3. independent

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    13
    Likes Received:
    1
    Maybe because your posted code does not contain the DIVs where your posting your results?
    You need something like this in the body:
    Code (Text):

    <div id ='hotel1'></div>
    <div id ='hotel2'></div>
     
    JS and HTML work together and both must be coded/posted to make sense of it.
     
    sunfighter, Dec 1, 2019
    #3
  4. independent

    independent

    Joined:
    Nov 23, 2019
    Messages:
    14
    Likes Received:
    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: Dec 1, 2019
    independent, Dec 1, 2019
    #4
  5. independent

    Flow495

    Joined:
    Dec 1, 2019
    Messages:
    3
    Likes Received:
    0
    Can i get some help on this Project, it says Develop a Triad class that represents a trinity of numbers and contains a method for equality checking two triads. Develop child class Date with fields that represent the year, month and day and also contains a full set of methods for equality checking two dates.
     
    Flow495, Dec 1, 2019
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.