MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Weather App using Fetch API & Async/Await0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
15.1Weather App using Fetch API & Async/Await
HomeTutorialsJavaScript for IntermediateWeather App using Fetch API & Async/Await

Weather App using Fetch API & Async/Await

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

In this capstone project for the Intermediate JavaScript module, you will build a production-ready Weather Dashboard Application. This project integrates the Fetch API, async/await, DOM manipulation, loading states, error boundaries, and real-time meteorological API data.


1. Project Specifications

  1. 1
    Weather API Integration: Connect to Open-Meteo or OpenWeather API to retrieve current conditions, temperature, humidity, and wind speed.
  2. 2
    City Geocoding: Convert city names (e.g. "Tokyo", "London", "New York") into geographic coordinates via geocoding API.
  3. 3
    Async Workflow: Clean async/await pipeline with centralized try...catch.
  4. 4
    UI State Management: Loading spinners, temperature toggle (°C / °F), and descriptive weather condition cards.

2. HTML Markup (index.html)

1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>SkyCast: Real-Time Weather</title>
7 <link rel="stylesheet" href="style.css" />
8</head>
9<body>
10 <div class="weather-card">
11 <header class="card-header">
12 <h1>SkyCast Weather</h1>
13 <form id="search-form" class="search-form">
14 <input type="text" id="city-input" placeholder="Enter city name (e.g. Paris)..." required />
15 <button type="submit" id="btn-search">Search</button>
16 </form>
17 </header>
18 
19 <div id="loader" class="loader hidden">
20 <div class="spinner"></div>
21 <p>Fetching weather data...</p>
22 </div>
23 
24 <div id="error-box" class="error-box hidden"></div>
25 
26 <main id="weather-display" class="weather-display hidden">
27 <div class="location-row">
28 <h2 id="city-name">City, Country</h2>
29 <span id="condition-badge" class="badge">Sunny</span>
30 </div>
31 
32 <div class="temp-row">
33 <div id="temperature" class="temp-val">22°C</div>
34 </div>
35 
36 <div class="metrics-grid">
37 <div class="metric">
38 <span class="label">Wind Speed</span>
39 <span id="wind-speed" class="val">12 km/h</span>
40 </div>
41 <div class="metric">
42 <span class="label">Relative Humidity</span>
43 <span id="humidity" class="val">65%</span>
44 </div>
45 </div>
46 </main>
47 </div>
48 
49 <script src="app.js"></script>
50</body>
51</html>

3. Styling the App (style.css)

1:root {
2 --primary: #0284c7;
3 --bg: #030712;
4 --card: #111827;
5 --text: #f9fafb;
6 --text-muted: #9ca3af;
7 --border: #1f2937;
8 --danger: #ef4444;
9}
10 
11body {
12 margin: 0;
13 font-family: system-ui, -apple-system, sans-serif;
14 background: var(--bg);
15 color: var(--text);
16 min-height: 100vh;
17 display: flex;
18 align-items: center;
19 justify-content: center;
20 padding: 1rem;
21}
22 
23.weather-card {
24 background: var(--card);
25 border: 1px solid var(--border);
26 border-radius: 1.25rem;
27 max-width: 480px;
28 width: 100%;
29 padding: 2rem;
30 box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
31}
32 
33.search-form {
34 display: flex;
35 gap: 0.5rem;
36 margin: 1.5rem 0;
37}
38 
39.search-form input {
40 flex: 1;
41 padding: 0.75rem 1rem;
42 border-radius: 0.5rem;
43 border: 1px solid var(--border);
44 background: #1f2937;
45 color: var(--text);
46 font-size: 1rem;
47}
48 
49.search-form button {
50 background: var(--primary);
51 color: white;
52 border: none;
53 padding: 0.75rem 1.25rem;
54 border-radius: 0.5rem;
55 font-weight: 600;
56 cursor: pointer;
57}
58 
59.location-row {
60 display: flex;
61 justify-content: space-between;
62 align-items: center;
63}
64 
65.badge {
66 background: rgba(2, 132, 199, 0.2);
67 color: #38bdf8;
68 padding: 0.25rem 0.75rem;
69 border-radius: 9999px;
70 font-size: 0.85rem;
71}
72 
73.temp-val {
74 font-size: 4rem;
75 font-weight: 800;
76 margin: 1rem 0;
77 color: #38bdf8;
78}
79 
80.metrics-grid {
81 display: grid;
82 grid-template-columns: 1fr 1fr;
83 gap: 1rem;
84 margin-top: 1.5rem;
85 padding-top: 1.5rem;
86 border-top: 1px solid var(--border);
87}
88 
89.metric {
90 background: #1f2937;
91 padding: 1rem;
92 border-radius: 0.5rem;
93 display: flex;
94 flex-direction: column;
95 gap: 0.25rem;
96}
97 
98.metric .label { font-size: 0.8rem; color: var(--text-muted); }
99.metric .val { font-size: 1.2rem; font-weight: 600; }
100 
101.error-box {
102 background: rgba(239, 68, 68, 0.15);
103 color: var(--danger);
104 padding: 1rem;
105 border-radius: 0.5rem;
106 margin: 1rem 0;
107}
108 
109.loader {
110 display: flex;
111 flex-direction: column;
112 align-items: center;
113 padding: 2rem 0;
114 color: var(--text-muted);
115}
116 
117.spinner {
118 width: 40px;
119 height: 40px;
120 border: 4px solid var(--border);
121 border-top-color: var(--primary);
122 border-radius: 50%;
123 animation: spin 0.8s linear infinite;
124 margin-bottom: 0.75rem;
125}
126 
127@keyframes spin { to { transform: rotate(360deg); } }
128.hidden { display: none !important; }

4. Application Logic (app.js)

Visual Architecture & Process Flow

How data and code flow step-by-step

Flowchart
Step 1
// 1. Geocoding Service (City
Step 2
Coordinates)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is encodeURIComponent(city) used when building the geocoding API URL?
Question 2
How does the app handle sequential API calls (geocoding coordinates first, then fetching weather)?
Question 3
What is the purpose of the interpretWeatherCode() helper function?
Question 4
What happens in handleWeatherSearch if the user inputs an invalid city that doesn't exist?
Question 5
Why is setLoading(false) executed in the finally block of handleWeatherSearch?

Related Lessons

Previous LessonNext Lesson
Product Filter AppNone

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
Previous
PreviousPrevNext