-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
131 lines (81 loc) · 3.12 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather App</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background: url('weatherapp.jpg-.jpg') no-repeat center center fixed;
background-size: cover;
color: antiquewhite;
font-family: Arial, sans-serif;
text-align: center;
background: url('scearyweather.jpg.jpg') no-repeat center center fixed;
background-size: cover;
color: antiquewhite;
}
h1, label, button {
color: antiquewhite;
}
#weather-info {
color: white; /* Set the text color to white */
}
#copyright {
color: antiquewhite;
}
</style>
</head>
<body background="scearyweather.jpg.jpg">
<h1>if you want to know any city weather temperatures, type the city name here</h1>
<label for="city">Enter city:</label>
<input type="text" id="city" placeholder="Enter city">
<button onclick="getWeather()" style="background-color: black; color: white;">Click here</button>
<div id="weather-info"></div>
<div id="weather-info"></div>
<div id="copyright">
<ul class="menu">
<li>© Developed by </li><li>Malamin Jagana</li>
</ul>
</div>
<script>
function getWeather() {
var apiKey = '0a1dbaca535bd791623022df86bdc1f3';
var city = document.getElementById('city').value;
if (city === '') {
alert('Please enter a city.');
return;
}
var apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
displayWeather(data);
})
.catch(error => {
console.error('Error fetching weather data:', error);
alert('Error fetching weather data. Please try again.');
});
}
function displayWeather(data) {
var weatherInfo = document.getElementById('weather-info');
weatherInfo.innerHTML = '';
if (data.cod !== 200) {
weatherInfo.innerHTML = `<p>${data.message}</p>`;
return;
}
var cityName = data.name;
var temperature = data.main.temp;
var description = data.weather[0].description;
var weatherHtml = `
<h2>${cityName}</h2>
<p>Temperature: ${temperature}°C</p>
<p>Description: ${description}</p>
`;
weatherInfo.innerHTML = weatherHtml;
}
</script>
</body>
</html>