Skip to content

Commit c1495dc

Browse files
committed
fixed day extrapolation
1 parent f2bf187 commit c1495dc

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

js/wmain.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ weatherConditions.onload = function() {
3030
if (weatherConditions.status === 200) {
3131
wCond = JSON.parse(weatherConditions.responseText);
3232
console.log(wCond);
33-
document.getElementById('location').innerHTML = wCond.name;
33+
document.getElementById('location').innerText = wCond.name;
3434
const iconcode = wCond.weather[0].icon;
3535
console.log("GOT icon = "+ iconcode);
3636
const iconpath = "https://openweathermap.org/img/w/"+iconcode+".png";
@@ -44,16 +44,16 @@ weatherConditions.onload = function() {
4444
if (i !== wCond.weather.length-1){
4545
weatherCond += ", ";}
4646
}
47-
document.getElementById('weather').innerHTML = weatherCond;
48-
document.getElementById('temperature').innerHTML = Math.round(wCond.main.temp);
49-
document.getElementById('windspeed').innerHTML = wCond.wind.speed.toFixed();
47+
document.getElementById('weather').innerText = weatherCond;
48+
document.getElementById('temperature').innerText = Math.round(wCond.main.temp);
49+
document.getElementById('windspeed').innerText = wCond.wind.speed.toFixed();
5050
let weatherDesc = "";
5151
for (let i=0; i < wCond.weather.length; i++) {
5252
weatherDesc += wCond.weather[i].description;
5353
if (i !== wCond.weather.length-1){
5454
weatherDesc += ", ";}
5555
}
56-
document.getElementById('desc').innerHTML = weatherDesc;
56+
document.getElementById('desc').innerText = weatherDesc;
5757
//document.getElementById('radar').src = 'https://tile.openweathermap.org/map/precipitation_new/4/6/10.png?appid=8c6405207db6b6fe115ac161f770cd31' // for radar div
5858
} //end if
5959
}; //end function
@@ -65,16 +65,16 @@ if (weatherForecast.status === 200){
6565
console.log(fObj);
6666
// day 1
6767
const d1 = new Date();
68-
const dayWeek = d1.getDay();
69-
const weekday1 = [];
70-
weekday1[0] = "Sunday";
71-
weekday1[1] = "Monday";
72-
weekday1[2] = "Tuesday";
73-
weekday1[3] = "Wednesday";
74-
weekday1[4] = "Thursday";
75-
weekday1[5] = "Friday";
76-
weekday1[6] = "Saturday";
77-
const day1 = weekday1[dayWeek];
68+
const dayWeek = d1.getDay(); console.log(`day is ${dayWeek}`);
69+
const weekday = [];
70+
weekday[0] = "Sunday";
71+
weekday[1] = "Monday";
72+
weekday[2] = "Tuesday";
73+
weekday[3] = "Wednesday";
74+
weekday[4] = "Thursday";
75+
weekday[5] = "Friday";
76+
weekday[6] = "Saturday";
77+
const day1 = weekday[dayWeek]; console.log(`day2 is ${day1}`);
7878
let day2, day3;
7979
document.getElementById('r1c1').innerHTML = day1;
8080
document.getElementById('r1c3').innerHTML = Math.round(fObj.list[0].main.temp)+"&deg;";
@@ -84,11 +84,12 @@ if (weatherForecast.status === 200){
8484

8585
// day 2
8686
if (dayWeek === 6) {
87-
day2 = weekday1[0];
87+
day2 = weekday[0];
8888
}
8989
else {
90-
day2 = weekday1[dayWeek+1];
90+
day2 = weekday[dayWeek+1];
9191
}
92+
console.log(`day2 is ${day2}`);
9293
document.getElementById('r2c1').innerHTML = day2;
9394
document.getElementById('r2c3').innerHTML = Math.round(fObj.list[8].main.temp)+"&deg;";
9495
document.getElementById('r2c2').src = "https://openweathermap.org/img/w/"+fObj.list[8].weather[0].icon+".png";
@@ -97,14 +98,15 @@ if (weatherForecast.status === 200){
9798

9899
// day 3
99100
if (dayWeek === 5) {
100-
day3 = weekday1[0];
101+
day3 = weekday[0];
101102
}
102103
else if (dayWeek === 6) {
103-
day3 = weekday1[1];
104+
day3 = weekday[1];
104105
}
105106
else {
106-
day3 = weekday1[dayWeek+1];
107+
day3 = weekday[dayWeek+2];
107108
}
109+
console.log(`day is ${day3}`);
108110
document.getElementById('r3c1').innerHTML = day3;
109111
document.getElementById('r3c3').innerHTML = Math.round(fObj.list[16].main.temp)+"&deg;";
110112
document.getElementById('r3c2').src = "https://openweathermap.org/img/w/"+fObj.list[16].weather[0].icon+".png";

weather_ins.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2>JSON data via OpenWeatherMap.org API</h2>
4444
<!-- page content here -->
4545
<main>
4646
<section id="left">
47-
<div id="location">City UT</div>
47+
<div id="location">City HSV</div>
4848
<div id="weathccondicon">
4949
<img src="imageplaceholder" alt="current weather" id="wcicon">
5050
</div>

0 commit comments

Comments
 (0)