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

105
Visualizações
getting NaN while showing data

I am getting NaN while retrieving the temperature, but I am getting the temperature correctly when i display it on console.

my code is shown below:

// Event listener to add function to existing HTML DOM element
generate.addEventListener('click', function performAction() {
  const zip = document.getElementById('zip').value;
  const feelings = document.getElementById('feelings').value;

  getData(baseURL, zip, apiKey)
    .then(function (data) {
      postData('/addData', { temperature: data.main.temp.toString(), date: newDate, feel: feelings })
    })
    .then(() => retrieveData());

})

/* Function to GET Project Data */
const retrieveData = async () => {
  const request = await fetch('/all');
  try {
    // Transform into JSON
    const allData = await request.json()
    console.log(allData)
    // Write updated data to DOM elements
    document.getElementById('temp').innerHTML = Math.round(allData.temp) + 'degrees';
    document.getElementById('content').innerHTML = allData.feel;
    document.getElementById("date").innerHTML = allData.date;
  }
  catch (error) {
    console.log("error", error);
    // appropriately handle the error
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If allData = {temperature: '277.32', date: '3.8.2022', feel: 'd'} then you must use allData.temperature not allData.temp

about 4 years ago · Juan Pablo Isaza Relatório
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