-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
112 lines (77 loc) · 3.29 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
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
var input_section = document.getElementsByClassName('input-section');
var alert_text = document.getElementById("alert_text");
var button = document.querySelector(".location_button");
var inputField = document.querySelector("input");
var tem = document.querySelector(".tem-text");
button.addEventListener("click", function(){
fetch('https://api.openweathermap.org/data/2.5/weather?q='+inputField.value+'&appid=4f415838509611f520feb293a7a4f1d1')
.then(response => response.json())
.then(data => {
// VAR INITIZALIZATION
var location = document.querySelector(".location");
var wind = document.querySelector("#wind");
var humidity = document.querySelector("#humidity");
var clouds = document.querySelector("#clouds");
// DATA FROM API
var nameValue = data['name'];
var tempValue = data['main']['temp'];
var windValue = data['wind']['speed'];
var humidityValue = data['main']['humidity'];
var cloudsValue = data['clouds']['all'];
// VALUE DISPLAYING
tem.innerHTML = tempValue.toFixed()-"273";
location.innerHTML = nameValue;
wind.innerHTML = windValue;
humidity.innerHTML = humidityValue;
clouds.innerHTML = cloudsValue;
console.log(data);
if(tempValue>=295){
document.getElementById('image').src = 'sun.gif';
}else if(tempValue>=290){
document.getElementById('image').src = 'rain.gif';
}else{
document.getElementById('image').src = 'snow.gif';
}
})
.catch(error => {
swal("Location Error", "Entered location is not found !", "error");
var alertCon = document.querySelector(".alertTop");
var resultSec = document.querySelector(".result-section");
var inputSec = document.querySelector('.input-section');
inputSec.style.display = "block";
inputField.value ="";
resultSec.style.display = "none";
alertCon.style.display = "none";
})
})
function mainFun(){
var inputField = document.querySelector("input");
var alertCon = document.querySelector(".alertTop");
var resultSec = document.querySelector(".result-section");
var inputSec = document.querySelector('.input-section');
if(inputField.value ==""){
swal("Empty Input", "Please input the location", "info");
}else{
inputSec.style.display = "none";
resultSec.style.display = "grid";
alertCon.style.display = "block";
alert_text.innerHTML = "SUCCESS";
alertTop.style.display = "block";
}
}
// DISPLAY ELEMENTS
function funOnload(){
var alertCon = document.querySelector(".alertTop");
var resultSec = document.querySelector(".result-section");
resultSec.style.display = "none";
alertCon.style.display = "none";
}
function backFun(){
var alertCon = document.querySelector(".alertTop");
var resultSec = document.querySelector(".result-section");
var inputSec = document.querySelector('.input-section');
if(alertCon.style.display = "none"){
inputSec.style.display = "block";
resultSec.style.display = "none";
}
}