Is there a way to save data retrieved from an API into localStorage when a button is clicked?
After executing the following code, I would like to store the obtained result:
function getResults(query) {
fetch(`https://cors-anywhere.herokuapp.com/https://api.openweathermap.org/data/2.5/find?q=${query}&units=metric&APPID=XXXXXX`)
.then(weather => {
return weather.json()
})
.then(displayResults)
}
function displayResults(weather) {
console.log(weather)
let city = document.querySelector('.cityy')
city.innerHTML = `${weather.list[0].name}`
let temp = document.querySelector('.current')
temp.innerHTML = `${weather.list[0].main.temp}`
let descr = document.querySelector('.description')
descr.innerHTML = `${weather.list[0].weather[0].description}`
}
Here's my button:
<input class="butt2" type="button" value="+"/>