Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
famous-programming-languages

Weather App In Javascript With Source Code

Posted on July 30, 2023January 1, 2026 By Rishabh saini No Comments on Weather App In Javascript With Source Code

Title: Create an Advanced JavaScript Project – Day 2

Welcome back Weather App In Javascript, fellow developers! In our journey to enhance our JavaScript skills, we are now on Day 2 of our advanced JavaScript project. If you missed Day 1, don’t worry; you can find it here. Today, we will continue building upon our previous work and create a dynamic web application using HTML, CSS, and, of course, JavaScript.

famous-programming-languages

Weather App In Javascript

Table of Contents

  1. Title: Create an Advanced JavaScript Project – Day 2
    1. Weather App In Javascript
  2. Project Overview: Weather Forecast Application
  3. Prerequisites
  4. Project Setup
  5. HTML Structure (index.html)
  6. CSS Styling (styles.css)
  7. JavaScript Logic (script.js)

Project Overview: Weather Forecast Application

In this project, we’ll be building a weather forecast application that allows users to check the current weather conditions of any city. We’ll be utilizing the power of the OpenWeatherMap API to fetch real-time weather data. The application will display the weather conditions along with a simple weather icon representing the weather type.

Weather App In Javascript
Weather App In Javascript

Prerequisites

Before we get started, make sure you have the following:

  1. A basic understanding of HTML, CSS, and JavaScript.
  2. A code editor (e.g., Visual Studio Code, Sublime Text, etc.).
  3. A modern web browser.

Project Setup

  1. Create a new folder named “WeatherApp” on your computer.
  2. Inside the “WeatherApp” folder, create three files: “index.html,” “styles.css,” and “script.js.”

HTML Structure (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Weather Forecast App</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div class="container">
    <h1>Weather Forecast App</h1>
    <input type="text" id="cityInput" placeholder="Enter a city">
    <button id="searchBtn">Search</button>
    <div id="weatherInfo">
      <!-- Weather information will be displayed here -->
    </div>
  </div>
  <script src="script.js"></script>
</body>
</html>

CSS Styling (styles.css)

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
}

.container {
  max-width: 400px;
  margin: 50px auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

h1 {
  text-align: center;
}

input[type="text"] {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007BFF;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

JavaScript Logic (script.js)

// Get DOM elements
const cityInput = document.getElementById('cityInput');
const searchBtn = document.getElementById('searchBtn');
const weatherInfo = document.getElementById('weatherInfo');

// OpenWeatherMap API key
const apiKey = 'your_openweathermap_api_key_here';

// Event listener for the search button
searchBtn.addEventListener('click', () => {
  const city = cityInput.value.trim();
  if (city === '') {
    alert('Please enter a city name.');
    return;
  }
  getWeatherData(city);
});

// Function to fetch weather data from OpenWeatherMap API
async function getWeatherData(city) {
  try {
    const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`);
    const data = await response.json();

    // Display weather information
    displayWeatherInfo(data);
  } catch (error) {
    console.error('Error fetching data:', error);
    alert('An error occurred while fetching weather data. Please try again later.');
  }
}

// Function to display weather information
function displayWeatherInfo(data) {
  const { name, weather, main } = data;
  const weatherDescription = weather[0].description;
  const temperature = (main.temp - 273.15).toFixed(1); // Convert Kelvin to Celsius

  weatherInfo.innerHTML = `
    <h2>${name}</h2>
    <p>${weatherDescription}</p>
    <p>Temperature: ${temperature}°C</p>
  `;
}
Weather App In Javascript
Weather App In Javascript

Putting it all Together

  1. Save all the above code into their respective files: “index.html,” “styles.css,” and “script.js.”
  2. Replace 'your_openweathermap_api_key_here' in the script.js file with your actual OpenWeatherMap API key. You can sign up for a free API key on the OpenWeatherMap website.
  3. Open the index.html file in your web browser, and you should see the Weather Forecast Application.

Conclusion

Congratulations! You’ve successfully created a Weather App In Javascript Application using HTML, CSS, and JavaScript. You’ve learned how to fetch data from an external API and dynamically display it on a web page.

After completing Day 2, keep exploring and enhancing your JavaScript skills. Stay tuned for the next blog post, where we’ll be adding more exciting features to our Weather App In Javascript!

Happy coding! Weather App In Javascript

Post Views: 1,039
Javascript Project

Post navigation

Previous Post: How to create a todo list in javascript
Next Post: Online House Rental System Project In PHP With Source Code

More Related Articles

Amazon clone using ReactJS Amazon clone using ReactJS and Firebase with Source Code and Guide Free Projects
how to create an OLX clone using React OLX Clone Using React.js Free Source Code Javascript Project
How To Create an Icon Bar with Html CSS - Image 10 How To Create an Icon Bar with Html CSS Javascript Project

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Secrets How to Design Digital Clock using JavaScript !
  2. Build a Signature Pad in HTML, CSS, JS & Canvas
  3. How to Create a Promo Code using html css Js (Free Source Code)
  4. File Sharing App With Free Source Code
  5. Day Management App [Advance Todo App]
  6. E-Waste Facility Locator

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,615)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,217)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,870)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme