From 0ac4dcffb0b42f31d1c4801053fa816eab7d3fa6 Mon Sep 17 00:00:00 2001 From: Robert Woodruff Date: Thu, 28 Jan 2021 21:23:53 -0500 Subject: [PATCH 1/4] completed part 1, working on part 2 --- .DS_Store | Bin 0 -> 6148 bytes css/main.css | 0 index.html | 9 +++++++-- js/weather.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 css/main.css create mode 100644 js/weather.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..06a67145c62920bbddd9bea200b591407d2ab4b8 GIT binary patch literal 6148 zcmeHK!EO^V5FMu}^`=7PfK)C>d*N0^37`rNNZXJedO$*5L=OeEyKK~~v|U%(P16!m z?Prv);5YaKK8L=sP1L028bRfe#&0~HvE}ELy+cHzJ4!l4O(K#|#+rxb4&iauTT-*0 zRiNNGb~E)Q&Qy#(Pw3>|XMoSHPAQ$xF%=8vw~evZZ!LNwv$%L%oZ55#8J}ipQMTK^ zL~W(M`e04UhHN}+d=3X{9F|czD!S3|fP3$wau8elgHqYdj^dALe|*?{{8r^vh!-X=}%riXZyw0bn3~CXPq~@ zM<*9wC*P)*SLP@LzEdraEdGJ-FlPHZ3x|28@?-coz5#x6N~llg)S>~EU@KeT>IdR( za^=w;?a(&$=pC?yjATATJYC2@*NJ1mG2j?j5(D-wlME`YA>%KgCa=THyED00tH-gYZDykASAZHI9L$GH?xCEOjaX literal 0 HcmV?d00001 diff --git a/css/main.css b/css/main.css new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html index 3233671..0b978dd 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,14 @@ - Document + + Weather App -

Hola Mundo

+

Welcome to the Weather App!

+ +

+

+ \ No newline at end of file diff --git a/js/weather.js b/js/weather.js new file mode 100644 index 0000000..57d9a23 --- /dev/null +++ b/js/weather.js @@ -0,0 +1,46 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART ONE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +//Step 1. Creates an XMLHttp Request Object +let xhr = new XMLHttpRequest(); +let xhrTwo = new XMLHttpRequest(); + +// commented out until part 2 is completed - let zipCode = prompt("What is your zip code?"); + +setLocation(); + +//Step 2. Create a callback function (Asyncronous) +xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === 200) { + let locationResponse = JSON.parse(xhr.responseText); + let latitude = locationResponse.places[0].latitude; + let longitude = locationResponse.places[0].longitude; + //console.log(locationResponse); + document.getElementById('zipCode').innerHTML = locationResponse.places[0]["place name"] + ", " + locationResponse.places[0]["state abbreviation"]; + } else if (xhr.status === 404) { + alert = "404 error, Response Not Found"; + } +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART TWO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +xhrTwo.onreadystatechange = function() { + if (xhrTwo.readyState === 4 && xhrTwo.status === 200) { + let weatherResponse = JSON.parse(xhrTwo.responseText); + console.log(weatherResponse); + document.getElementById('weather').innerHTML = weatherResponse; + } +} +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +//Step 3. Open request +xhr.open('GET', 'http://api.zippopotam.us/US/' + zipCode); +xhr.open('GET', 'http://www.7timer.info/bin/api.pl'); + +//Step 4. Send request +function sendAJAX() { + xhr.send(); + } + +function setLocation() { + let zipCode + } \ No newline at end of file From 013b6b44b27783db838b445d89eb5c309cc4b98f Mon Sep 17 00:00:00 2001 From: Robert Woodruff Date: Fri, 29 Jan 2021 00:19:14 -0500 Subject: [PATCH 2/4] completed part 1, working on part 2 --- js/weather.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/js/weather.js b/js/weather.js index 57d9a23..99db80f 100644 --- a/js/weather.js +++ b/js/weather.js @@ -3,44 +3,45 @@ //Step 1. Creates an XMLHttp Request Object let xhr = new XMLHttpRequest(); let xhrTwo = new XMLHttpRequest(); - -// commented out until part 2 is completed - let zipCode = prompt("What is your zip code?"); - -setLocation(); +let zipCode = 90210; //prompt("Enter zip code to get City, State, and Weather?"); +let lon; +let lat; //Step 2. Create a callback function (Asyncronous) xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { let locationResponse = JSON.parse(xhr.responseText); - let latitude = locationResponse.places[0].latitude; - let longitude = locationResponse.places[0].longitude; - //console.log(locationResponse); - document.getElementById('zipCode').innerHTML = locationResponse.places[0]["place name"] + ", " + locationResponse.places[0]["state abbreviation"]; + lon = locationResponse.places[0].longitude; + lat = locationResponse.places[0].latitude; + let city = locationResponse.places[0]["place name"]; + let state = locationResponse.places[0]["state abbreviation"]; + // console.log(locationResponse); + console.log(lon); + console.log(lat); + document.getElementById('zipCode').innerHTML = city + ", " + state; } else if (xhr.status === 404) { alert = "404 error, Response Not Found"; } } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART TWO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ xhrTwo.onreadystatechange = function() { if (xhrTwo.readyState === 4 && xhrTwo.status === 200) { let weatherResponse = JSON.parse(xhrTwo.responseText); + let temp = weatherResponse.dataseries[0].weather; console.log(weatherResponse); - document.getElementById('weather').innerHTML = weatherResponse; + document.getElementById('weather').innerHTML = temp; } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Step 3. Open request -xhr.open('GET', 'http://api.zippopotam.us/US/' + zipCode); -xhr.open('GET', 'http://www.7timer.info/bin/api.pl'); +xhr.open('GET', 'http://api.zippopotam.us/US/'+zipCode); +//xhrTwo.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&output=json&lon=' + lon + "&lat=" + lat); +xhrTwo.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&output=json&lon=-118.4065&lat=34.0901'); //Step 4. Send request function sendAJAX() { xhr.send(); - } - -function setLocation() { - let zipCode + xhrTwo.send(); } \ No newline at end of file From 55c6a245a376018e0a12dd5aaeca666886f00082 Mon Sep 17 00:00:00 2001 From: Robert Woodruff Date: Fri, 29 Jan 2021 20:57:29 -0500 Subject: [PATCH 3/4] part 2 coded but incorrect weather type returned with variables being passed --- js/weather.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/js/weather.js b/js/weather.js index 99db80f..c7071ab 100644 --- a/js/weather.js +++ b/js/weather.js @@ -2,8 +2,9 @@ //Step 1. Creates an XMLHttp Request Object let xhr = new XMLHttpRequest(); -let xhrTwo = new XMLHttpRequest(); -let zipCode = 90210; //prompt("Enter zip code to get City, State, and Weather?"); +let xhr2 = new XMLHttpRequest(); + +const zipCode = 19143; //prompt("Enter zip code to get City, State, and Weather?"); let lon; let lat; @@ -15,7 +16,7 @@ xhr.onreadystatechange = function() { lat = locationResponse.places[0].latitude; let city = locationResponse.places[0]["place name"]; let state = locationResponse.places[0]["state abbreviation"]; - // console.log(locationResponse); + console.log(locationResponse); console.log(lon); console.log(lat); document.getElementById('zipCode').innerHTML = city + ", " + state; @@ -25,9 +26,9 @@ xhr.onreadystatechange = function() { } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART TWO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -xhrTwo.onreadystatechange = function() { - if (xhrTwo.readyState === 4 && xhrTwo.status === 200) { - let weatherResponse = JSON.parse(xhrTwo.responseText); +xhr2.onreadystatechange = function() { + if (xhr2.readyState === 4 && xhr2.status === 200) { + let weatherResponse = JSON.parse(xhr2.responseText); let temp = weatherResponse.dataseries[0].weather; console.log(weatherResponse); document.getElementById('weather').innerHTML = temp; @@ -36,12 +37,17 @@ xhrTwo.onreadystatechange = function() { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Step 3. Open request + xhr.open('GET', 'http://api.zippopotam.us/US/'+zipCode); -//xhrTwo.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&output=json&lon=' + lon + "&lat=" + lat); -xhrTwo.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&output=json&lon=-118.4065&lat=34.0901'); + +//Below code returns the incorrect weather type of lightrain when passing the values via declared variables +//xhr2.open('GET', `http://www.7timer.info/bin/api.pl?product=civillight&lon=${lon}&lat=${lat}&output=json`); + +//If hard coded, correct weather type is returned +xhr2.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&lon=-75.2288&lat=39.9448&output=json'); //Step 4. Send request function sendAJAX() { xhr.send(); - xhrTwo.send(); + xhr2.send(); } \ No newline at end of file From ffbe7d5b7c91c51f7dd62658f9af245c355bf9ee Mon Sep 17 00:00:00 2001 From: Robert Woodruff Date: Sun, 31 Jan 2021 23:58:46 -0500 Subject: [PATCH 4/4] submission with part 2 --- .DS_Store | Bin 6148 -> 6148 bytes css/main.css | 0 css/weather.css | 7 ++++ index.html | 12 ++++--- js/.DS_Store | Bin 0 -> 6148 bytes js/weather.js | 93 +++++++++++++++++++++++------------------------- 6 files changed, 58 insertions(+), 54 deletions(-) delete mode 100644 css/main.css create mode 100644 css/weather.css create mode 100644 js/.DS_Store diff --git a/.DS_Store b/.DS_Store index 06a67145c62920bbddd9bea200b591407d2ab4b8..eeb26559bbe408e95c6ef4a6e347aab8b8686d24 100644 GIT binary patch delta 184 zcmZoMXfc=|#>B!ku~2NHo+2ar#(>?7ix)66F|u#wVG3syWMar-C{8LbE=bDBPhwzT zI62vesUcRPy4uLhKu5vY#H3b7q1w_2$Tl%HtF7ha5LY#{^-RdEtg5c5t(ytd0R)VU z5SoD>O2epGKnB=`vf!e;ocz3WAfIt_0`oS;&Fmcf96)z%p2+;2c{0CB)qu~2NHo+2ab#(>?7jI5h^Si%`Mhp=sC+}QAuX)`+qKL=3FW - + Weather App

Welcome to the Weather App!

- -

-

- + +
+

+

+ +
\ No newline at end of file diff --git a/js/.DS_Store b/js/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0`; + loc.innerHTML = city + ", " + state; + // } else if (xhr.status === 404) { + // alert = "404 error, Response Not Found"; + } } + xhr.open('GET', `http://api.zippopotam.us/US/${zipCode}`); + xhr.send(); } -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART TWO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -xhr2.onreadystatechange = function() { - if (xhr2.readyState === 4 && xhr2.status === 200) { - let weatherResponse = JSON.parse(xhr2.responseText); - let temp = weatherResponse.dataseries[0].weather; - console.log(weatherResponse); - document.getElementById('weather').innerHTML = temp; - } -} -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -//Step 3. Open request - -xhr.open('GET', 'http://api.zippopotam.us/US/'+zipCode); - -//Below code returns the incorrect weather type of lightrain when passing the values via declared variables -//xhr2.open('GET', `http://www.7timer.info/bin/api.pl?product=civillight&lon=${lon}&lat=${lat}&output=json`); - -//If hard coded, correct weather type is returned -xhr2.open('GET', 'http://www.7timer.info/bin/api.pl?product=civillight&lon=-75.2288&lat=39.9448&output=json'); + let xhr2 = new XMLHttpRequest(); + xhr2.onreadystatechange = function() { + if (xhr2.readyState === 4 && xhr2.status === 200) { + let weatherResponse = JSON.parse(xhr2.responseText); + //let forcast = weatherResponse.dataseries[0].weather; + min = weatherResponse['dataseries'][0]['temp2m'].min * 9 / 5 + 32; + max = weatherResponse['dataseries'][0]['temp2m'].max * 9 / 5 + 32; + //let tempAvg = (min + max) / 2; + console.log(weatherResponse); + //.innerHTML = Math.floor(max); + temp.innerHTML = Math.floor(max) + `°F`.sup(); + + //document.getElementById('weather').innerHTML = Math.floor(max)+`°F`.sup(); + } + } -//Step 4. Send request -function sendAJAX() { - xhr.send(); +function getWeather(lon, lat) { + xhr2.open('GET', `http://www.7timer.info/bin/api.pl?product=civillight&lon=${lon}&lat=${lat}&output=json`); xhr2.send(); - } \ No newline at end of file +} \ No newline at end of file