sagar1250 / C-Programming

0 stars 0 forks source link

Creating a Weather App #1

Open sagar1250 opened 1 year ago

sagar1250 commented 1 year ago

HTML File Code (index.html)

<!DOCTYPE html>

My Weather App

Weather for

Temperature

  • Temperature is
  • Min Temperature is
  • Max Temperature is

Humidity Info

%

  • Humidity is
  • Cloud PCT is
  • Feels Like

Wind Info

km/hr

  • Wind speed is
  • Sunrise Time is
  • Sunset Time is

Weather of other common places

< <
cloud_pct Feels_like Humidity Max_temp Min_temp Sunrise Sunset Temp Wind_degrees Wind_speed
Shanghai 1 2 3 4 5 1 2 3 4 5
Boston 1 2 3 4 5 1 2 3 4 5
Lucknow1 2 3 4 5 1 2 3 4 5
Kolkata1 2 3 4 5 1 2 3 4 5

JavaScript Code (script.js)

const options = { method: 'GET', headers: { 'X-RapidAPI-Key': '47f7b10910msh54245c99856fc89p1511ebjsn0be081069aa6', 'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com' } }; const getWeather = (city) => { cityName.innerHTML = city fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city, options) .then(response => response.json()) .then((response) => { console.log(response) cloud_pct.innerHTML = response.cloud_pct temp.innerHTML = response.temp temp2.innerHTML = response.temp feels_like.innerHTML = response.feels_like humidity.innerHTML = response.humidity humidity2.innerHTML = response.humidity min_temp.innerHTML = response.min_temp max_temp.innerHTML = response.max_temp wind_speed.innerHTML = response.wind_speed wind_speed2.innerHTML = response.wind_speed wind_degrees.innerHTML = response.wind_degrees sunrise.innerHTML = response.sunrise sunset.innerHTML = response.sunset

    })
    .catch(err => console.error(err));

} submit.addEventListener("click", (e) => { e.preventDefault() getWeather(city.value) }) getWeather("Delhi")

OutPut

Image

sagar1250 commented 1 year ago

Image