Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda