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

103
Views
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 answers
Answer question

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 Report
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!