-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeather_Forcasting_app.html
More file actions
115 lines (99 loc) · 2.73 KB
/
Weather_Forcasting_app.html
File metadata and controls
115 lines (99 loc) · 2.73 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!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: 'Poppins', sans-serif;
background: linear-gradient(to right, #83a4d4, #b6fbff);
height: 100vh;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
}
.weather-card {
background: white;
padding: 30px;
border-radius: 16px;
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
width: 300px;
text-align: center;
transition: transform 0.2s;
}
.weather-card:hover {
transform: scale(1.02);
}
h2 {
margin-bottom: 10px;
}
input {
width: 80%;
padding: 8px;
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 6px;
outline: none;
}
button {
margin-top: 15px;
padding: 10px 15px;
border: none;
background-color: #007bff;
color: white;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.temp {
font-size: 2rem;
margin-top: 15px;
color: #333;
}
.error {
color: red;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="weather-card">
<h2>Weather App 🌤️</h2>
<input type="text" id="cityInput" placeholder="Enter city name" />
<button onclick="getWeather()">Check Weather</button>
<div id="result"></div>
</div>
<script>
async function getWeather() {
const city = document.getElementById("cityInput").value.trim();
const resultDiv = document.getElementById("result");
if (!city) {
resultDiv.innerHTML = "<p class='error'>Please enter a city name.</p>";
return;
}
const apiKey = "a7c00f0792ac4e6880e44457252010";
const url = `http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${city}&aqi=yes`;
resultDiv.innerHTML = "<p>Loading...</p>";
try {
const response = await fetch(url);
if (!response.ok) throw new Error("City not found");
const data = await response.json();
const temp = data.current.temp_c;
const condition = data.current.condition.text;
const icon = data.current.condition.icon;
resultDiv.innerHTML = `
<div class="temp">${temp}°C</div>
<p>${condition}</p>
<img src="https:${icon}" alt="weather icon">
`;
} catch (error) {
resultDiv.innerHTML = `<p class='error'>${error.message}</p>`;
}
}
</script>
</body>
</html>