I am writing simple JS app that shows weather. After first query variables like
searchTerm
array
innerHTML
const form = document.querySelector('#searchForm'); const currentTemp = document.querySelector('#temp'); const feelingTemp = document.querySelector('#feelingTemp'); const button = document.querySelector('button'); const img = document.createElement('img'); const searchCity = document.querySelector('#searchingCity'); const sky = document.querySelector('#skyStatus'); const bg_image = document.querySelector('.left-container'); const moreInfo = document.querySelector('.right-container'); const getWeather = async () => { try{ const searchTerm = form.elements.query.value const res = await axios.get(`https://api.openweathermap.org/data/2.5/weather?q={Math.floor(resTemp)}°C`) if(resSkyIcon === 'Clear'){ img.src = "./img/sun.png" let finalImg = document.querySelector('#skyStatus') finalImg.appendChild(img) bg_image.style.backgroundImage = "url('img/sunny_bg.jpg')" }else if(resSkyIcon === 'Clouds'){ img.src = "./img/cloud.png" let finalImg = document.querySelector('#skyStatus') finalImg.appendChild(img) bg_image.style.backgroundImage = "url('img/cloud_bg.jpg')" }else{ img.src = "./img/rain.png" let finalImg = document.querySelector('#skyStatus') finalImg.appendChild(img) bg_image.style.backgroundImage = "url('img/rain_bg.jpg')" } // Right box const array = [ `Feels temp
{Math.floor(resTempMin)}°C`, `Temp max
{resPressure}HPa`, `Humidity ${resHumidity}%` ] const ul = document.querySelector('ul'); array.forEach((value) =>{ const li = document.createElement('li'); li.innerText = value ul.appendChild(li) }) }) } runApp();
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>WeatherApp - Rob</title> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="left-container"> <div class="form-container"> <form id="searchForm"> <input type="text" placeholder="Weather in" name="query" id="searchInput"> </form> </div> <div class="weather-output"> <h2 id="temp"></h2> <h2 id="searchingCity"></h2> <h2 id="skyStatus"></h2> </div> <div class="right-container"> <h2 id="right-header">Informacje dodatkowe</h2> <div class="more-info-container"> <ul></ul> </div> </div> </div> <script src="./app2.js"></script> </body> </html>
Anonymous Asked question May 13, 2021
Recent Comments