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
}
}
If allData = {temperature: '277.32', date: '3.8.2022', feel: 'd'} then you must use allData.temperature not allData.temp