Repository navigation
Expand file tree
/
Copy pathjava.js
More file actions
92 lines (79 loc) · 2.95 KB
/
Copy pathjava.js
File metadata and controls
92 lines (79 loc) · 2.95 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
var self = this;
var sum = 0;
function getWeatherData(city) {
"use strict";
$.ajax({
type: 'GET',
dataType: 'json',
url: "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&APPID=b6fff70a1df60ee9c14b03d5c9f976e1",
success: function(data) {
console.log(data);
$('#myModalLabel').html(data.name);
$('#main').html(data.weather[0].main);
$('#description').html(data.weather[0].description);
$('#temp').html(' ' + data.main.temp + '°C');
$('#pressure').html('  ' + data.main.pressure + ' hpa');
$('#humidity').html(data.main.humidity +' %');
$('#temp_min').html(data.main.temp_min + '°C');
$('#temp_max').html(data.main.temp_max + '°C');
$('#wind').html(data.wind.speed + ' m/s');
$('#icon').attr('src','img/' + data.weather[0].main + '.png');
}
});}
$('#searchButton').click(function() {
"use strict";
var city = $('#inputCity').val();
getWeatherData(city);
$('#inputCity').val('');
});
function getWeatherDataAverage(city) {
"use strict";
$.ajax({
type: 'GET',
dataType: 'json',
url: "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&APPID=b6fff70a1df60ee9c14b03d5c9f976e1",
success: function(data) {
console.log(data);
sum = sum + Number(data.main.temp);
$('#averageBody').append("<p class='cities' style='color:black'>" + "Temperature of " + city[0].toUpperCase() + city.slice(1) + " is " + data.main.temp + '°C' + "</p>");
}
});}
$('#averageButton').click(function() {
"use strict";
$('#averageBody').empty();
var city1 = $('#inputCity1').val();
var city2 = $('#inputCity2').val();
var city3 = $('#inputCity3').val();
var city4 = $('#inputCity4').val();
getWeatherDataAverage(city1);
getWeatherDataAverage(city2);
getWeatherDataAverage(city3);
getWeatherDataAverage(city4);
$(document).ajaxStop(function() {
console.log(sum/4);
sum = sum / 4;
if(sum){
sum = sum.toPrecision(4);
$('#averageBody').append("<br>");
$('#averageBody').append("<p id='averagetemp' style='color:green'>" + "Average Temperature is " + sum.toString() + '°C' + "</p>");
sum = 0;
}
})
$('#averageBody').empty();
});
console.log('done!!');
$(document).ready(function() {
"use strict";
setTimeout(function(){
$('body').addClass('loaded');
$('h1').css('color','#222222');
}, 3000);
});
function clearfields() {
"use strict";
document.getElementById("uname").value = "";
document.getElementById("pword").value = "";
document.getElementById("email").value = "";
document.getElementById("aname").value = "";
}
clearfields();