Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Fixed Previous forecast elements in the 'forecast-container' are not cleared when fetching newer ones. #5
  • Loading branch information
kshitizrohilla authored Jul 17, 2024
1 parent fe0e824 commit 7f93c0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
19 changes: 11 additions & 8 deletions scripts/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ cityInputMobile.addEventListener("keyup", function (event) {
.then(response => response.json())
.then(data => {
const forecastContainer = document.getElementById('forecast-container');

forecastContainer.innerHTML = '';

const dailyForecasts = {};
data.list.forEach(entry => {
const dateTime = new Date(entry.dt * 1000);
Expand Down Expand Up @@ -91,14 +94,14 @@ cityInputMobile.addEventListener("keyup", function (event) {
forecastCard.classList.add('daily-forecast-card');

forecastCard.innerHTML = `
<p class="daily-forecast-date">${day.date}</p>
<div class="daily-forecast-logo"><img class="imgs-as-icons" src="${day.icon}"></div>
<div class="max-min-temperature-daily-forecast">
<span class="max-daily-forecast">${Math.round(day.maxTemp - 273.15)}<sup>o</sup>C</span>
<span class="min-daily-forecast">${Math.round(day.minTemp - 273.15)}<sup>o</sup>C</span>
</div>
<p class="weather-type-daily-forecast">${day.weatherType}</p>
`;
<p class="daily-forecast-date">${day.date}</p>
<div class="daily-forecast-logo"><img class="imgs-as-icons" src="${day.icon}"></div>
<div class="max-min-temperature-daily-forecast">
<span class="max-daily-forecast">${Math.round(day.maxTemp - 273.15)}<sup>o</sup>C</span>
<span class="min-daily-forecast">${Math.round(day.minTemp - 273.15)}<sup>o</sup>C</span>
</div>
<p class="weather-type-daily-forecast">${day.weatherType}</p>
`;

forecastContainer.appendChild(forecastCard);
});
Expand Down
20 changes: 12 additions & 8 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ cityInput.addEventListener("keyup", function (event) {
.then(response => response.json())
.then(data => {
const forecastContainer = document.getElementById('forecast-container');

forecastContainer.innerHTML = '';

const dailyForecasts = {};
data.list.forEach(entry => {
const dateTime = new Date(entry.dt * 1000);
Expand Down Expand Up @@ -118,14 +121,14 @@ cityInput.addEventListener("keyup", function (event) {
forecastCard.classList.add('daily-forecast-card');

forecastCard.innerHTML = `
<p class="daily-forecast-date">${day.date}</p>
<div class="daily-forecast-logo"><img class="imgs-as-icons" src="${day.icon}"></div>
<div class="max-min-temperature-daily-forecast">
<span class="max-daily-forecast">${Math.round(day.maxTemp - 273.15)}<sup>o</sup>C</span>
<span class="min-daily-forecast">${Math.round(day.minTemp - 273.15)}<sup>o</sup>C</span>
</div>
<p class="weather-type-daily-forecast">${day.weatherType}</p>
`;
<p class="daily-forecast-date">${day.date}</p>
<div class="daily-forecast-logo"><img class="imgs-as-icons" src="${day.icon}"></div>
<div class="max-min-temperature-daily-forecast">
<span class="max-daily-forecast">${Math.round(day.maxTemp - 273.15)}<sup>o</sup>C</span>
<span class="min-daily-forecast">${Math.round(day.minTemp - 273.15)}<sup>o</sup>C</span>
</div>
<p class="weather-type-daily-forecast">${day.weatherType}</p>
`;

forecastContainer.appendChild(forecastCard);
});
Expand All @@ -135,6 +138,7 @@ cityInput.addEventListener("keyup", function (event) {
});



document.getElementById("locationName").innerHTML = location;
document.getElementById("temperatureValue").innerHTML = temperature + "<sup>o</sup>C";
document.getElementById("weatherType").innerHTML = weatherType;
Expand Down

0 comments on commit 7f93c0a

Please sign in to comment.