This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
(() => {
|
||||
// dev/assets/js/main.js
|
||||
(() => {
|
||||
const DOM = {
|
||||
weatherBox: document.querySelector(".weather-box"),
|
||||
weatherIcon: document.querySelector(".weather-pic img"),
|
||||
figcaption: document.querySelector("figcaption"),
|
||||
description: document.querySelector(".description"),
|
||||
temp: document.querySelector(".temp"),
|
||||
tempMin: document.querySelector(".temp-min"),
|
||||
tempMax: document.querySelector(".temp-max"),
|
||||
windIcon: document.querySelector(".wind-icon"),
|
||||
speed: document.querySelector(".speed"),
|
||||
deg: document.querySelector(".deg")
|
||||
weatherBox: document.querySelector('.weather-box'),
|
||||
weatherIcon: document.querySelector('.weather-pic img'),
|
||||
figcaption: document.querySelector('figcaption'),
|
||||
description: document.querySelector('.description'),
|
||||
temp: document.querySelector('.temp'),
|
||||
tempMin: document.querySelector('.temp-min'),
|
||||
tempMax: document.querySelector('.temp-max'),
|
||||
windIcon: document.querySelector('.wind-icon'),
|
||||
speed: document.querySelector('.speed'),
|
||||
deg: document.querySelector('.deg'),
|
||||
};
|
||||
console.log(DOM);
|
||||
const API_KEY = "";
|
||||
const API_KEY = '';
|
||||
const LAT = 43.72072300281546;
|
||||
const LON = 7.352450291796612;
|
||||
const TEMP_MAX_ALERT_AMOUNT = 30;
|
||||
const TEMP_MIN_ALERT_AMOUNT = 10;
|
||||
const init = () => {
|
||||
console.log("init!");
|
||||
console.log('init!');
|
||||
getWeather().then((data) => {
|
||||
console.log(data);
|
||||
if (data) {
|
||||
DOM.weatherBox.classList.add("show", "animate__flipInX");
|
||||
DOM.weatherBox.classList.add('show', 'animate__flipInX');
|
||||
setWeather(data);
|
||||
}
|
||||
});
|
||||
@@ -33,9 +33,9 @@
|
||||
const getWeather = async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${LAT}&lon=${LON}&units=metric&appid=${API_KEY}`
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${LAT}&lon=${LON}&units=metric&appid=${API_KEY}`,
|
||||
);
|
||||
if (!res.ok) throw new Error("Fetch Error");
|
||||
if (!res.ok) throw new Error('Fetch Error');
|
||||
const data = await res.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
@@ -57,9 +57,9 @@
|
||||
DOM.weatherIcon.src = `https://openweathermap.org/img/wn/${icon}@2x.png`;
|
||||
DOM.windIcon.style.transform = `rotate(${Number(deg) - 45}deg)`;
|
||||
if (Number(temp) >= TEMP_MAX_ALERT_AMOUNT) {
|
||||
DOM.temp.classList.add("danger");
|
||||
DOM.temp.classList.add('danger');
|
||||
} else if (Number(temp) <= TEMP_MIN_ALERT_AMOUNT) {
|
||||
DOM.temp.classList.add("frozen");
|
||||
DOM.temp.classList.add('frozen');
|
||||
}
|
||||
};
|
||||
init();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
console.log(DOM);
|
||||
|
||||
// BITTE EIGENEN API KEY VERWENDEN
|
||||
// (NICHT DIESEN KEY VERWENDEN: b62eaccfd1a09cf1d04b00bd2ec689e7)
|
||||
const API_KEY = '';
|
||||
const LAT = 43.72072300281546;
|
||||
const LON = 7.352450291796612;
|
||||
|
||||
Reference in New Issue
Block a user