Spaces:
Running
Running
Update index.html
Browse files- index.html +99 -19
index.html
CHANGED
|
@@ -1,19 +1,99 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>Weather web</title>
|
| 8 |
+
<link rel="stylesheet" href="style.css">
|
| 9 |
+
</head>
|
| 10 |
+
|
| 11 |
+
<body>
|
| 12 |
+
|
| 13 |
+
<div class="card">
|
| 14 |
+
<div class="search">
|
| 15 |
+
<input type="text" placeholder="Enter City Name" spellcheck="false">
|
| 16 |
+
<button> <img src="https://cdn3.iconfinder.com/data/icons/feather-5/24/search-512.png" alt="Search">
|
| 17 |
+
</button>
|
| 18 |
+
</div>
|
| 19 |
+
<div class="error">
|
| 20 |
+
<p>
|
| 21 |
+
Invalid city name
|
| 22 |
+
</p>
|
| 23 |
+
</div>
|
| 24 |
+
<div class="weather">
|
| 25 |
+
<img src="https://t4.ftcdn.net/jpg/03/38/74/43/360_F_338744374_c8v4RyKnToRWqPA4SalFf8ktaMQA48QW.jpg"
|
| 26 |
+
alt="rain" class="weather-icon">
|
| 27 |
+
<h1 class="temp">25°c</h1>
|
| 28 |
+
<h2 class="city">Bhilai</h2>
|
| 29 |
+
<div class="detail">
|
| 30 |
+
<div class="col">
|
| 31 |
+
<img src="https://static-00.iconduck.com/assets.00/humidity-icon-2048x1675-xxsge5os.png"
|
| 32 |
+
alt="humidity">
|
| 33 |
+
<div>
|
| 34 |
+
<p class="Humidity">50%</p>
|
| 35 |
+
<p>Humidity</p>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
<div class="col">
|
| 39 |
+
<img src="https://cdn-icons-png.flaticon.com/512/54/54298.png" alt="Wind">
|
| 40 |
+
<div>
|
| 41 |
+
<p class="Wind">7.6 km/h</p>
|
| 42 |
+
<p>Wind speed</p>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
|
| 49 |
+
<script>
|
| 50 |
+
const apikey = "b8af2f72455a7c9ae28dabbb0e29b4a9";
|
| 51 |
+
const apiUrl = "https://api.openweathermap.org/data/2.5/weather?&units=metric&q=";
|
| 52 |
+
|
| 53 |
+
const searchBox = document.querySelector(".search input");
|
| 54 |
+
const searchBtn = document.querySelector(".search button");
|
| 55 |
+
const weatherIcon = document.querySelector(".weather-icon");
|
| 56 |
+
|
| 57 |
+
async function checkWeather(city) {
|
| 58 |
+
const response = await fetch(apiUrl + city + `&appid=${apikey}`);
|
| 59 |
+
if (response.status == 404) {
|
| 60 |
+
document.querySelector(".error").style.display = "block";
|
| 61 |
+
document.querySelector(".weather").style.display = "none";
|
| 62 |
+
}
|
| 63 |
+
else {
|
| 64 |
+
var data = await response.json();
|
| 65 |
+
|
| 66 |
+
document.querySelector(".city").innerHTML = data.name;
|
| 67 |
+
document.querySelector(".temp").innerHTML = Math.round(data.main.temp) + "°c";
|
| 68 |
+
document.querySelector(".Humidity").innerHTML = data.main.humidity + "%";
|
| 69 |
+
document.querySelector(".Wind").innerHTML = data.wind.speed + " km/h";
|
| 70 |
+
|
| 71 |
+
if (data.weather[0].main == "Clouds") {
|
| 72 |
+
weatherIcon.scr = "https://cdn-icons-png.flaticon.com/512/4834/4834559.png";
|
| 73 |
+
}
|
| 74 |
+
else if (data.weather[0].main == "Clear") {
|
| 75 |
+
weatherIcon.src = "https://static-00.iconduck.com/assets.00/weather-clear-symbolic-icon-2048x2048-v4afvu7m.png";
|
| 76 |
+
}
|
| 77 |
+
else if (data.weather[0].main == "Rain") {
|
| 78 |
+
weatherIcon.src = "https://cdn2.iconfinder.com/data/icons/weather-flat-14/64/weather07-512.png";
|
| 79 |
+
}
|
| 80 |
+
else if (data.weather[0].main == "Drizzle") {
|
| 81 |
+
weatherIcon.src = "https://cdn-icons-png.flaticon.com/512/1458/1458966.png";
|
| 82 |
+
}
|
| 83 |
+
else if (data.weather[0].main == "Mist") {
|
| 84 |
+
weatherIcon.src = "https://cdn-icons-png.flaticon.com/512/4005/4005901.png";
|
| 85 |
+
}
|
| 86 |
+
document.querySelector(".weather").style.display = "block";
|
| 87 |
+
document.querySelector(".error").style.display = "none";
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
}
|
| 93 |
+
searchBtn.addEventListener("click", () => {
|
| 94 |
+
checkWeather(searchBox.value);
|
| 95 |
+
})
|
| 96 |
+
</script>
|
| 97 |
+
</body>
|
| 98 |
+
|
| 99 |
+
</html>
|