-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (25 loc) · 1.05 KB
/
script.js
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
window.addEventListener("load", resp => {
// https://www.weather.gov/documentation/services-web-api
let weatherLink = ""
let textbox = document.getElementById("textbox")
let allButtons = document.getElementById("buttonsBar").childNodes
textbox.addEventListener("keypress", buttonPress => {
if(buttonPress.key == "Enter") {
location.href = "https://www.google.com/search?q=" + textbox.value
}
})
fetch(weatherLink).then(resp => {
resp.json().then(jsonData => {
console.log(jsonData)
let weatherTemp = document.getElementById("weatherTextTemp")
let forecastFor = document.getElementById("forecastFor")
forecastFor.innerText = jsonData["properties"]["periods"][0]["shortForecast"]
weatherTemp.innerText = jsonData["properties"]["periods"][0]["temperature"]
})
})
for(let button of allButtons) {
button.onclick = function() {
location.href = this.getAttribute("linkTo")
}
}
})