Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Why am I getting TypeError: null is not an object (evaluating 'hotelName.textContent = hotel.name')

Fellow Devs.

I keep getting this TypeError and don't know why exactly or how to fix the problem. Everthing seems to look alright but still, it's not displaying the HTML.

It's saying that hotelName.textContent = hotel.name; is null and not an object.

(function() {
   var hotel = { 
        name: 'Park',
        roomRate: 230,
        discount: 15,
        offerPrice: function() { 
            var offerRate = this.roomRate * ((100 - this.discount) / 100);
            return offerRate;
        }
    }

    var hotelName, roomRate, specialRate; // Declare Variables

    hotelName = document.getElementById('hotelName'); // Get elements
    roomRate = document.getElementById('roomRate');
    specialRate = document.getElementById('specialRate');

    hotelName.textContent = hotel.name; // write hotel name
    roomRate.textContent = '$' + hotel.roomRate.toFixed(2); // write room rate
    specialRate.textContent = '$' + hotel.offerPrice(); // write offer price

// Part Two: Calculate and write out the expiry details for the offer
    var expiryMsg; // The messaged displayed to users
    var today; // Today's date
    var elEnds; // The message that shows the message about the offer ending

    function offerExpires(today) {
        // Declaring Variables within the function for local scope
        var weekFromToday, day, date, month, year, dayNames, monthNames;
        // Add 7 days time (added in milliseconds)
        weekFromToday = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000); // This is our expiration date
        // Creates an array of days/ months
        dayNames = ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
        monthNames = ['January', 'February', 'March', 'April', 'May','June','July', 'August', 'September', 'November', 'December'];
        // Collect the parts of the dates to show on the page
        day = dayNames[weekFromToday.getDay()]; // Gets day of the week
        date = weekFromToday.getDate();
        month = monthNames[weekFromToday.getMonth()];
        year = weekFromToday.getFullYear();
        //Create the message
        expiryMsg = 'Offer expires next ';
        expiryMsg += day + '<br/>(' + date + '' + month + '' + year + ')';
        return expiryMsg;
    }

    today = new Date(); // Puts today's date in a variable
    elEnds = document.getElementById('offerEnds'); // Get the offerEnds element
    elEnds.innerHTML = offerExpires(today); // add the expiry msg
// Finish the immediate invoked function expression
}());
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!