forked from code-differently/Weather-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (67 loc) · 2.64 KB
/
index.js
File metadata and controls
95 lines (67 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function getWeather() {
let userZip = document.getElementById("userZip").value;
weatherByZip = new XMLHttpRequest();
weatherByZip.open("GET", `http://api.zippopotam.us/us/${userZip}`, true);
weatherByZip.onload = function() {
return userZip;
}
weatherByZip.onreadystatechange = function() {
if (weatherByZip.readyState === 4 && weatherByZip.status === 200) {
let data = JSON.parse(weatherByZip.response)
console.log(data)
document.getElementById("data").src = data.responseText
let city = data.places[0]["place name"]
let state = data.places[0]["state abbreviation"]
document.getElementById("weatherByZip").innerHTML = `${city}, ${state}`;
}
}
let getLongitude = data.places.longitude;
let getLatitude = data.places.latitude;
weatherData = new XMLHttpRequest();
weatherData.open("GET", `http://www.7timer.info/bin/astro.php?lon=113.17&lat=23.09&ac=0&lang=en&unit=metric&output=internal&tzshift=0`, true);
//request long and lat data from zippo
weatherByZip.send();
}
// function newDogPic() {
// let dogs = new XMLHttpRequest();
// dogs.onreadystatechange = function() {
// if (this.readyState === 4 && this.status === 200) {
// let doggy = JSON.parse(this.response);
// document.getElementById("dogPic1").src = doggy.message[0];
// document.getElementById("dogPic2").src = doggy.message[1];
// document.getElementById("dogPic3").src = doggy.message[2];
// }
// };
// dogs.open('GET', `https://dog.ceo/api/breeds/image/random/3`, true);
// dogs.send();
// }
// // Input Element to get number
// // Button to trigger fetch (onclick)
// // Call the Pokemons (rest request sent to server)
// // Update HTML
// let sampleData = {
// "id": 8,
// "name": "Wartortle",
// "img": "https://img.pokemondb.net/sprites/bank/normal/wartortle.png"
// }
// function updateHTML(data) {
// document.getElementById("img").src = data.img;
// document.getElementById("name").innerText = data.name;
// }
// updateHTML(sampleData);
// //
// function getPokemonData(id) {
// let xhttp = new XMLHttpRequest();
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// let data = JSON.parse(this.response)
// updateHTML(data);
// }
// };
// xhttp.open("GET", `https://127.0.0.1:3000/pokemon/${id}`, true);
// xhttp.send();
// }
// function updatePokemon() {
// document.getElementById("pokemonId").value;
// getPokemonData(pokemonId);
// }