commit 03e1462931ef08db4d8eae67b69cc1ce053b454c
parent 3d59c0a6836c821242a9040e3b3c1a4cae612daa
Author: Johs <[email protected]>
Date: Sun, 11 Jun 2023 16:35:47 +0200
Windchill displayed and ranked
Diffstat:
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/js/panda.js b/js/panda.js
@@ -1,23 +1,28 @@
let token = ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
+let windchills = [];
fetch(`http://localhost:8080/api/${token}`)
- .then(response => response.clone().json())
- .then(data => {
+ .then(response => response.json())
+ .then(data=> {
+ data.forEach(weatherdata =>{
+ windchills.push(weatherdata)
+ })
+ windchills.sort(jsonSorter('windchill'));
let weatherList = document.getElementById('weather-list');
- data.forEach(item => {
+ windchills.forEach(item => {
let listItem = document.createElement('li');
- listItem.textContent = item['windchill'] + ' ' + item['humidity'];
+ listItem.textContent = item['windchill'] + " degrees Celsius";
weatherList.appendChild(listItem);
- });
+ })
});
function jsonSorter(key) {
return function(a, b) {
if (a[key] > b[key]) {
- return 1;
- } else if (a[key] < b[key]) {
return -1;
+ } else if (a[key] < b[key]) {
+ return 1;
}
return 0;
}
diff --git a/views/panda.html b/views/panda.html
@@ -60,7 +60,7 @@
<div class="block1">
<div class="content">
- <ol class="fancy-list" id="weather-list"></ol>
+ <ol id="weather-list"></ol>
</div>
<div class="content1">