File tree Expand file tree Collapse file tree 4 files changed +11
-11
lines changed
test/manual-test-examples Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,8 @@ function getWeather() {
3636
3737 var cityName = userInput . value ( ) ;
3838 var URL =
39- 'http://api.openweathermap.org/data/2.5/weather?q=' +
40- cityName +
41- '&units=metric' ;
39+ 'https://wttr.in/' + encodeURIComponent ( cityName ) + '?format=j1' ;
40+
4241 result = loadJSON ( URL , displayWeather ) ; // displayWeather is the callback
4342}
4443
@@ -47,9 +46,9 @@ function displayWeather() {
4746 print ( result ) ; // result is ready!
4847
4948 var location = result . name ;
50- var currentTemp = result . main . temp ;
49+ var avgTemp = result . weather [ 0 ] . avgtempC ;
5150 text (
52- 'Current temperature in ' + location + ' is ' + currentTemp + ' celsius' ,
51+ 'Today\'s average temperature in ' + location + ' is ' + avgTemp + ' celsius' ,
5352 width / 2 ,
5453 height / 2
5554 ) ;
Original file line number Diff line number Diff line change 11function setup ( ) {
22 noCanvas ( ) ;
33 loadJSON (
4- 'http ://api.openweathermap.org/data/2.5/station?id=5091 ' ,
4+ 'https ://wttr.in/Berlin?format=j1 ' ,
55 parseStuff ,
66 'json'
77 ) ;
Original file line number Diff line number Diff line change 11// In this example, we want to load JSON (a JavaScript Object)
2- // from a URL at openweathermap.org , and display it in setup().
2+ // from a URL at wttr.in , and display it in setup().
33//
44// Since setup() happens faster than you can load a website, the
55// data does not have time to properly load before setup() is done.
@@ -13,7 +13,7 @@ var result;
1313
1414function preload ( ) {
1515 result = loadJSON (
16- 'http ://api.openweathermap.org/data/2.5/weather?id=5128581&units=imperial '
16+ 'https ://wttr.in/Berlin?format=j1 '
1717 ) ;
1818 console . log ( 'In preload(), the result has not finished loading: ' ) ;
1919 console . log ( result ) ;
@@ -29,10 +29,10 @@ function setup() {
2929 console . log ( 'In setup(), here is the result: ' ) ;
3030 console . log ( result ) ;
3131
32- var location = result . name ;
33- var currentTemp = result . main . temp ;
32+ var location = result . nearest_area [ 0 ] . areaName [ 0 ] . value ;
33+ var avgTemp = result . weather [ 0 ] . avgtempC ;
3434 text (
35- 'Current temperature in ' + location + ' is ' + currentTemp + 'F ' ,
35+ 'Today\'s average temperature in ' + location + ' is ' + avgTemp + ' celsius ' ,
3636 width / 2 ,
3737 height / 2
3838 ) ;
Original file line number Diff line number Diff line change 66 </ head >
77
88 < body >
9+ < p > Press the arrow keys, colors should change.</ p >
910 </ body >
1011</ html >
You can’t perform that action at this time.
0 commit comments