Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda