12/1/24, 6:30 PM app.
js
1 const apiKey = "790a086c68e03883d64b5a065f1e9232";
2 const searchBtn = [Link]("search-btn");
3 const cityNameInput = [Link]("city-name");
4
5 const cityElem = [Link]("city");
6 const descriptionElem = [Link]("description");
7 const tempElem = [Link]("temp");
8 const humidityElem = [Link]("humidity");
9 const windSpeedElem = [Link]("wind-speed");
10 const pressureElem = [Link]("pressure");
11
12 [Link]("click", function() {
13 const city = [Link];
14 if (city) {
15 getWeather(city);
16 }
17 });
18
19 async function getWeather(city) {
20 const url = `[Link]
q=${city}&appid=${apiKey}&units=metric`;
21
22 try {
23 const response = await fetch(url);
24 const data = await [Link]();
25
26 if ([Link] === "404") {
27 alert("City not found. Please try again.");
28 return;
29 }
30
31 const { name, weather, main, wind } = data;
32 [Link] = name;
33 [Link] = weather[0].description;
34 [Link] = `Temperature: ${[Link]}°C`;
35 [Link] = `Humidity: ${[Link]}%`;
36 [Link] = `Wind Speed: ${[Link]} m/s`;
37 [Link] = `Pressure: ${[Link]} hPa`;
38 } catch (error) {
39 alert("An error occurred while fetching weather data.");
40 }
41 }
42
localhost:4649/?mode=javascript 1/1