Skip to content

Commit

Permalink
Added Api data to the weather forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
Shemene committed Nov 26, 2023
1 parent 71573e4 commit 5e3490e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
35 changes: 25 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,42 @@ function getForecast(city) {
}

function displayForcast(response) {
let forecastHtml = "";

console.log(response.data);

let days = ["Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
let forecastHtml = "";

days.forEach(function (day) {
forecastHtml =
forecastHtml +
`
function formatDay(timestamp) {
let date = new Date(timestamp * 1000);
let days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
return days[date.getDay()];
}

response.data.daily.forEach(function (day, index) {
if (index < 5) {
forecastHtml =
forecastHtml +
`
<div class="weather-forecast-item">
<div class="weather-forecast-date">${day}</div>
<div class="weather-forecast-icon"> <img
src="http://shecodes-assets.s3.amazonaws.com/api/weather/icons/clear-sky-day.png"
<div class="weather-forecast-date">${formatDay(day.time)}</div>
<div > <img class="weather-forecast-icon"
src="${day.condition.icon_url}"
alt=""
width="36"
/> </div>
<div class="weather-forecast-temperatures">
<span class="weather-forecast-temperature-max">18°</span
><span class="weather-forecast-temperature-min">12°</span>
<span class="weather-forecast-temperature-max">${Math.round(
day.temperature.maximum
)}°</span>
<span class="weather-forecast-temperature-min">${Math.round(
day.temperature.minimum
)}°</span>
</div>
</div>
</div>`;
}
});
let forecastElement = document.querySelector("#forecast");
forecastElement.innerHTML = forecastHtml;
Expand Down
11 changes: 8 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ a {
}

.weather-forecast-temperatures {
font-size: 13px;
font-size: 20px;
}
.weather-forecast-temperature-min {
opacity: 0.5;
}
.weather-forecast-item {
display: inline-block;
margin: 10px;
padding: 10px;
margin: 5px;
padding: 5px;
}
weather-forecast-icon {
width: 50px;
height: 50px;
display: block;
}

0 comments on commit 5e3490e

Please sign in to comment.