-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (109 loc) · 3.75 KB
/
Copy pathscript.js
File metadata and controls
155 lines (109 loc) · 3.75 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var apikey = "192aa32e12efeef9298dceab17715f5a";
//search//
function search() {
var search_text = document.getElementById("search_text").value;
if (search_text == "") {
alert("Please enter a search term");
return false;
}
else {
return true;
}
}
//grab values from search to later use in our functions
//activity3 mod 6//
var submitButton = document.getElementById('searchBtn');
submitButton.addEventListener('click', function (event) {
event.preventDefault();
var input = document.getElementById('cityInput').value;
currentWeather(input)
//console.log(input)
})
function getApi() {
// fetch request gets a forecast of the weather
var requestUrl = '"https://api.openweathermap.org/data/2.5/direct?q="';
fetch(requestUrl)
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data)
//Loop over the data to generate a table, each table row will have a link to the repo url
// for (var i = 0; i < data.length; i++) {
// // Creating elements, tablerow, tabledata, and anchor
// var createTableRow = document.createElement('tr');
// var tableData = document.createElement('td');
// var link = document.createElement('a');
// // Setting the text of link and the href of the link
// link.textContent = data[i].html_url;
// link.href = data[i].html_url;
// // Appending the link to the tabledata and then appending the tabledata to the tablerow
// // The tablerow then gets appended to the tablebody
// tableData.appendChild(link);
// createTableRow.appendChild(tableData);
// tableBody.appendChild(createTableRow);
// }
});
}
//fetchButton.addEventListener('click', getApi);
//grab the search content//
//activity3 mod 7//
// fetchLocation(event);
// function fetchLocation(search) {
// if (navigator.geolocation) {
// navigator.geolocation.getCurrentPosition(showPosition);
// } else {
// alert("Geolocation is not supported by this browser.");
// }
// }
//functionality for fetching weather//
//functionality for rendering content//
var todaysWeather = $("#todaysWeather");
var today = $("#today");
var fiveDay = $("#fiveDay");
var search = $("#search");
var cities = [];
var savedCities = localStorage.getItem("cities") || [];
if (savedCities.length > 0) {
cities = savedCities;
}
function currentWeather (city) {
var url= `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apikey}&units=imperial`
fetch(url)
.then(res => res.json())
.then((data) => {
console.log(data)
var card = document.createElement("div");
var cityName = document.createElement("h3");
var tempEl = document.createElement("p");
cityName.textContent = data.name;
tempEl.textContent = "Temperature: " + data.main.temp;
card.append(cityName, tempEl);
var renderEl = document.getElementById("currentRender");
console.log(card)
renderEl.append(card);
});
}
function getLocation(data) {
console.log(data)
// var let = data.[0].lat;
// var lng = data.[0].lon;
// return { lat, lon };
var apikey = "192aa32e12efeef9298dceab17715f5a"
fetch(
"https://api.openweathermap.org/data/2.5/wonecall?late="
+ lat
+ "&lon="
+ lon
+ "units=imperial"
+ "&appid="
+ apikey
)
.then((response) => {
return response.json();
})
.then((data) => this.displayWeather(data));
}
// displayWeather: function (data) {
// return data;
//}