Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
10 views
1 page
app.js
Weather forecasting application Javascript code
Uploaded by
jayanthi.vm2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save app.js For Later
Download
Save
Save app.js For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
10 views
1 page
app.js
Weather forecasting application Javascript code
Uploaded by
jayanthi.vm2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save app.js For Later
Carousel Previous
Carousel Next
Download
Save
Save app.js For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 1
Search
Fullscreen
12/1/24, 6:30 PM app.
js
1 const apiKey = "790a086c68e03883d64b5a065f1e9232";
2 const searchBtn = document.getElementById("search-btn");
3 const cityNameInput = document.getElementById("city-name");
4
5 const cityElem = document.getElementById("city");
6 const descriptionElem = document.getElementById("description");
7 const tempElem = document.getElementById("temp");
8 const humidityElem = document.getElementById("humidity");
9 const windSpeedElem = document.getElementById("wind-speed");
10 const pressureElem = document.getElementById("pressure");
11
12 searchBtn.addEventListener("click", function() {
13 const city = cityNameInput.value;
14 if (city) {
15 getWeather(city);
16 }
17 });
18
19 async function getWeather(city) {
20 const url = `https://api.openweathermap.org/data/2.5/weather?
q=${city}&appid=${apiKey}&units=metric`;
21
22 try {
23 const response = await fetch(url);
24 const data = await response.json();
25
26 if (data.cod === "404") {
27 alert("City not found. Please try again.");
28 return;
29 }
30
31 const { name, weather, main, wind } = data;
32 cityElem.textContent = name;
33 descriptionElem.textContent = weather[0].description;
34 tempElem.textContent = `Temperature: ${main.temp}°C`;
35 humidityElem.textContent = `Humidity: ${main.humidity}%`;
36 windSpeedElem.textContent = `Wind Speed: ${wind.speed} m/s`;
37 pressureElem.textContent = `Pressure: ${main.pressure} hPa`;
38 } catch (error) {
39 alert("An error occurred while fetching weather data.");
40 }
41 }
42
localhost:4649/?mode=javascript 1/1
You might also like
Weather App Documentation
PDF
No ratings yet
Weather App Documentation
6 pages
PROGRAM 15 (2)
PDF
No ratings yet
PROGRAM 15 (2)
8 pages
Weather App HTML
PDF
No ratings yet
Weather App HTML
2 pages
WP Assignment
PDF
No ratings yet
WP Assignment
9 pages
weather_app_code
PDF
No ratings yet
weather_app_code
3 pages
Weather-Forecasting-Project
PDF
No ratings yet
Weather-Forecasting-Project
10 pages
Experiment 04
PDF
No ratings yet
Experiment 04
4 pages
NODE3
PDF
No ratings yet
NODE3
10 pages
Experiment_8_record_format
PDF
No ratings yet
Experiment_8_record_format
5 pages
taran2
PDF
No ratings yet
taran2
12 pages
new_documentiiiii
PDF
No ratings yet
new_documentiiiii
1 page
Find current weather of any city using Open Weather Map API in Python (1)
PDF
No ratings yet
Find current weather of any city using Open Weather Map API in Python (1)
6 pages
Weather
PDF
No ratings yet
Weather
1 page
good
PDF
No ratings yet
good
67 pages
Object23445rfgffhgf
PDF
No ratings yet
Object23445rfgffhgf
64 pages
Object23
PDF
No ratings yet
Object23
43 pages
Practical 9 (1)
PDF
No ratings yet
Practical 9 (1)
7 pages
Weather Forecasting Website
PDF
No ratings yet
Weather Forecasting Website
6 pages
Lab 13 Web Eng
PDF
No ratings yet
Lab 13 Web Eng
4 pages
Using Yahoo'S Apis To Build A Simple Weather Web Services: The Javascript
PDF
No ratings yet
Using Yahoo'S Apis To Build A Simple Weather Web Services: The Javascript
8 pages
Weather_App_Project
PDF
No ratings yet
Weather_App_Project
2 pages
d189c2d8-2646-4286-aad2-23e67a8424a2
PDF
No ratings yet
d189c2d8-2646-4286-aad2-23e67a8424a2
6 pages
Codec Input
PDF
No ratings yet
Codec Input
1 page
computer_pro
PDF
No ratings yet
computer_pro
19 pages
Industrial Programming (Python) - Case Study 2 - Puviyarasu A (4)
PDF
No ratings yet
Industrial Programming (Python) - Case Study 2 - Puviyarasu A (4)
5 pages
Detailed My Weather App Report
PDF
No ratings yet
Detailed My Weather App Report
2 pages
Weather Project
PDF
100% (1)
Weather Project
18 pages
Project Weather App
PDF
100% (1)
Project Weather App
17 pages
03 Adding A Forecast Graph
PDF
No ratings yet
03 Adding A Forecast Graph
23 pages
Historical Data
PDF
No ratings yet
Historical Data
6 pages
air23
PDF
No ratings yet
air23
2 pages
app.html
PDF
No ratings yet
app.html
1 page
EasyChair Preprint 10131
PDF
No ratings yet
EasyChair Preprint 10131
8 pages
weather ppt
PDF
No ratings yet
weather ppt
13 pages
Weather Components
PDF
No ratings yet
Weather Components
13 pages
ps6 22X002
PDF
No ratings yet
ps6 22X002
6 pages
EasyChair Preprint 10131
PDF
No ratings yet
EasyChair Preprint 10131
7 pages
Python Weather App Presentation
PDF
No ratings yet
Python Weather App Presentation
12 pages
Python_Weather_App_Presentation_With_Design
PDF
No ratings yet
Python_Weather_App_Presentation_With_Design
13 pages
Dev Challenges - Weather APP
PDF
No ratings yet
Dev Challenges - Weather APP
1 page
Weather App in Python 2.0
PDF
No ratings yet
Weather App in Python 2.0
6 pages
HW1
PDF
No ratings yet
HW1
25 pages
Project _Report_Shashwat (1)[1] (AutoRecovered)
PDF
No ratings yet
Project _Report_Shashwat (1)[1] (AutoRecovered)
13 pages
weather_app_full_report
PDF
No ratings yet
weather_app_full_report
16 pages
Weather App
PDF
No ratings yet
Weather App
11 pages
Miniproject (1) - Read-Only
PDF
No ratings yet
Miniproject (1) - Read-Only
14 pages
Chan
PDF
No ratings yet
Chan
7 pages
PWP sd
PDF
No ratings yet
PWP sd
5 pages
cThings Front-end Interview Task Instructions-1
PDF
No ratings yet
cThings Front-end Interview Task Instructions-1
2 pages
Kedar Py 123
PDF
No ratings yet
Kedar Py 123
14 pages
Bhaskar
PDF
No ratings yet
Bhaskar
20 pages
Bids by Weather
PDF
No ratings yet
Bids by Weather
11 pages
A Project of Computer Science Weather Forecasting Python Programming
PDF
No ratings yet
A Project of Computer Science Weather Forecasting Python Programming
11 pages
flutterdocument
PDF
No ratings yet
flutterdocument
10 pages
AJINKJ
PDF
No ratings yet
AJINKJ
5 pages
Javascript Assessment Test
From Everand
Javascript Assessment Test
Edward Yao
No ratings yet
Designing XSD diagrams vol1
From Everand
Designing XSD diagrams vol1
Jose Luis Arias Cobreros
No ratings yet
C Language Programming Codes
From Everand
C Language Programming Codes
Durgesh
No ratings yet
NgRx SignalStore: An effortless solution for state management
From Everand
NgRx SignalStore: An effortless solution for state management
Abdelfattah Ragab
No ratings yet
No Ph.D. Game Design With Three.js
From Everand
No Ph.D. Game Design With Three.js
Nikiforos Kontopoulos
No ratings yet
Python_Essentials_1_v1_0_Overview
PDF
No ratings yet
Python_Essentials_1_v1_0_Overview
1 page
bp (1)
PDF
No ratings yet
bp (1)
1 page
21CS743 Model Set 1 Paper
PDF
No ratings yet
21CS743 Model Set 1 Paper
1 page
DSV Module-2
PDF
No ratings yet
DSV Module-2
23 pages
DSV Module-1
PDF
No ratings yet
DSV Module-1
26 pages
CG Report
PDF
No ratings yet
CG Report
19 pages