├── assets ├── clear.svg ├── clouds.svg ├── drizzle.svg ├── humid.svg ├── mist.svg ├── rain.svg └── wind.svg ├── index.css ├── index.html └── index.js /assets/clear.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 93 | 94 | 95 | 96 | 98 | 99 | 100 | 102 | 103 | 104 | 106 | 107 | 108 | 110 | 111 | 112 | 114 | 115 | 116 | 118 | 119 | 120 | 122 | 123 | 124 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /assets/clouds.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 98 | 99 | 100 | 102 | 105 | 106 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /assets/drizzle.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 92 | 93 | 94 | 96 | 99 | 100 | 101 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /assets/humid.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /assets/mist.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /assets/rain.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 116 | 117 | 118 | 120 | 123 | 124 | 126 | 128 | 130 | 131 | 133 | 135 | 137 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /assets/wind.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /index.css: -------------------------------------------------------------------------------- 1 | *{ 2 | margin: 0; 3 | padding: 0; 4 | font-family: 'Times New Roman', Times, serif; 5 | box-sizing: border-box; 6 | } 7 | 8 | .Card{ 9 | width: 90%; 10 | max-width: 470px; 11 | background:linear-gradient(135deg, #00feba, #5b548a); 12 | color: #fff; 13 | margin: 100px auto 0; 14 | border-radius: 20px; 15 | padding: 40px 35px; 16 | text-align: center; 17 | 18 | } 19 | .search{ 20 | width: 100%; 21 | display: flex; 22 | align-items: center; 23 | justify-content: space-between; 24 | } 25 | .search input{ 26 | border: 0; 27 | outline: 0; 28 | background: #555; 29 | padding: 10px 25px; 30 | height: 60px; 31 | border-radius: 30px; 32 | flex: 1; 33 | margin-right: 16px; 34 | font-size: 18px; 35 | } 36 | 37 | .search button{ 38 | border: 0; 39 | outline: 0; 40 | background: #ebfffc; 41 | border-radius: 50%; 42 | width: 60px; 43 | height: 60px; 44 | cursor: pointer; 45 | } 46 | 47 | .weather-icon { 48 | width: 170px; 49 | margin-top: 30px; 50 | } 51 | 52 | .weather h1 { 53 | font-size: 80px; 54 | font-weight: 500; 55 | } 56 | 57 | .weather h2 { 58 | font-size: 45px; 59 | font-weight: 400; 60 | margin-top: -10px; 61 | } 62 | 63 | .details { 64 | display: flex; 65 | align-items: center; 66 | justify-content: space-between; 67 | padding: 0 20px; 68 | margin-top: 50px; 69 | } 70 | 71 | .col { 72 | display: flex; 73 | align-items: center; 74 | text-align: left; 75 | } 76 | 77 | .col img { 78 | width: 40px; 79 | margin-right: 10px; 80 | } 81 | 82 | .humidity, .wind { 83 | font-size: 28px; 84 | margin-top: -6px; 85 | } 86 | 87 | .weather { 88 | display: none; 89 | } 90 | 91 | .error { 92 | text-align: left; 93 | margin-left: 10px; 94 | font-size: 14px; 95 | margin-top: 10px; 96 | display: none; 97 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Weather App 8 | 9 | 10 |
11 | 15 | 16 |
17 |

Invalid city name

18 |
19 |
20 | 21 |

22°C

22 |

New York

23 |
24 |
25 | 26 |
27 |

50%

28 |

Humidity

29 |
30 |
31 |
32 | 33 |
34 |

15 km/h

35 |

Wind Speed

36 |
37 |
38 |
39 |
40 |
41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const apiKey = ""; // Sign up at https://openweathermap.org to get your free API key 2 | const apiUrl = "https://api.openweathermap.org/data/2.5/weather?units=metric&q="; 3 | 4 | const searchBox = document.querySelector(".search input"); 5 | const searchBtn = document.querySelector(".search button"); 6 | 7 | async function checkWeather(city) { 8 | try { 9 | const response = await fetch(apiUrl + city + `&appid=${apiKey}`); 10 | 11 | if(response.status == 404) { 12 | document.querySelector(".error").style.display = "block"; 13 | document.querySelector(".weather").style.display = "none"; 14 | } else { 15 | const data = await response.json(); 16 | 17 | document.querySelector(".city").innerHTML = data.name; 18 | document.querySelector(".temp").innerHTML = Math.round(data.main.temp) + "°C"; 19 | document.querySelector(".humidity").innerHTML = data.main.humidity + "%"; 20 | document.querySelector(".wind").innerHTML = data.wind.speed + " km/h"; 21 | 22 | // Update weather icon based on weather condition 23 | const weatherIcon = document.querySelector(".weather-icon"); 24 | if(weatherIcon) { 25 | switch(data.weather[0].main) { 26 | case "Clouds": 27 | weatherIcon.src = "assets/clouds.svg"; 28 | break; 29 | case "Clear": 30 | weatherIcon.src = "assets/clear.svg"; 31 | break; 32 | case "Rain": 33 | weatherIcon.src = "assets/rain.svg"; 34 | break; 35 | case "Drizzle": 36 | weatherIcon.src = "assets/drizzle.svg"; 37 | break; 38 | case "Mist": 39 | weatherIcon.src = "assets/mist.svg"; 40 | break; 41 | } 42 | } 43 | 44 | document.querySelector(".weather").style.display = "block"; 45 | document.querySelector(".error").style.display = "none"; 46 | } 47 | 48 | } catch(error) { 49 | console.error("Error fetching weather data:", error); 50 | } 51 | } 52 | 53 | searchBtn.addEventListener("click", () => { 54 | checkWeather(searchBox.value); 55 | }); 56 | 57 | searchBox.addEventListener("keypress", (event) => { 58 | if (event.key === "Enter") { 59 | checkWeather(searchBox.value); 60 | } 61 | }); --------------------------------------------------------------------------------