Estoy tratando de obtener un objeto y luego publicar su temperatura. aquí obtengo el objeto mediante la función getweather y luego hice la función postweather para publicar la fecha (variable que hice), el contenido (entrada del usuario) y la temperatura (temp del objeto que obtuve por api).
todo funciona muy bien, pero la temperatura se recupera como un objeto vacío a pesar de que consola. Lo registro y se imprime como un número.
async function getWeather(url) { fetch(url) .then((res) => { return res.json(); }) .then((data) => { // console.log(data); //save temp to globall variable globalThis.temp = data.main.temp; }) .catch((error) => console.log("error:", error)); postWeather("/post", temp); }// solo es divertido verificar la temperatura y está impreso en números
function noha() { console.log(temp); } //post async async function postWeather(url) { try { await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ date: newDate, temp, feelings }) }); } catch (error) { console.log("error post", error); } }