assets/js/script.js
// loop for today's main weather
loop for today's main weather
loop for today ' s main weather
function displayWeather(data, city) {
  if (data.list.length === 0) {
    weatherContainerEl.textContent = 'No weather found.';
    return;
  }
  cityNameEl.textContent = city + ", " + data.city.country;
  for (let i = 0; i < 1; i++) {
    var date = data.list[i].dt_txt;
    var temp = data.list[i].main.temp;
    var wind = data.list[i].wind.speed;
    var humidity = data.list[i].main.humidity;
    var iconWeather = data.list[i].weather[0].icon;
    var justDate = date.split(' ');
    var justTemp = Math.round(temp);
      dateEl = document.createElement('h4');
      var formatDate = moment(justDate[0]).format('dddd, MMMM Do YYYY');
      dateEl.textContent = formatDate;
      weatherContainerEl.appendChild(dateEl);
      iconEl = document.createElement('img');
      iconEl.setAttribute('src', 'https://openweathermap.org/img/wn/' + iconWeather + '@2x.png');
      weatherContainerEl.appendChild(iconEl);
      tempEl = document.createElement('h4');
      tempEl.textContent = "Temp: " + justTemp + "\xB0C";
      weatherContainerEl.appendChild(tempEl);
      humidEl = document.createElement('h4');
      humidEl.textContent = "Humidity: " + humidity + "%";
      weatherContainerEl.appendChild(humidEl);
      windEl = document.createElement('h4');
      windEl.textContent = "Wind: " + wind + " km/h";
      weatherContainerEl.appendChild(windEl);
      var lat = data.city.coord.lat;
      var lon = data.city.coord.lon;
      getUvIndex(lat, lon);
      getFiveDay(data);
    }
}
function displayWeather ( data , city ) { if ( data . list . length === 0 ) { weatherContainerEl . textContent = 'No weather found.' ; return ; } cityNameEl . textContent = city + ", " + data . city . country ; for ( let i = 0 ; i < 1 ; i ++ ) { var date = data . list [ i ] . dt_txt ; var temp = data . list [ i ] . main . temp ; var wind = data . list [ i ] . wind . speed ; var humidity = data . list [ i ] . main . humidity ; var iconWeather = data . list [ i ] . weather [ 0 ] . icon ; var justDate = date . split ( ' ' ) ; var justTemp = Math . round ( temp ) ; dateEl = document . createElement ( 'h4' ) ; var formatDate = moment ( justDate [ 0 ] ) . format ( 'dddd, MMMM Do YYYY' ) ; dateEl . textContent = formatDate ; weatherContainerEl . appendChild ( dateEl ) ; iconEl = document . createElement ( 'img' ) ; iconEl . setAttribute ( 'src' , 'https://openweathermap.org/img/wn/' + iconWeather + '@2x.png' ) ; weatherContainerEl . appendChild ( iconEl ) ; tempEl = document . createElement ( 'h4' ) ; tempEl . textContent = "Temp: " + justTemp + "\xB0C" ; weatherContainerEl . appendChild ( tempEl ) ; humidEl = document . createElement ( 'h4' ) ; humidEl . textContent = "Humidity: " + humidity + "%" ; weatherContainerEl . appendChild ( humidEl ) ; windEl = document . createElement ( 'h4' ) ; windEl . textContent = "Wind: " + wind + " km/h" ; weatherContainerEl . appendChild ( windEl ) ; var lat = data . city . coord . lat ; var lon = data . city . coord . lon ; getUvIndex ( lat , lon ) ; getFiveDay ( data ) ; } }
loop for today's main weather
loop for today ' s main weather
// update city name in the html // shows the date // sets the weather icon // shows the temp // shows the humidity // shows the wind // get data to display UV index