Last active
January 24, 2023 01:33
-
-
Save matthieua/101d2938bf90069fccb7aa39c7565bf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<title>Weather API</title> | |
<style> | |
h1 { | |
color: #6443ea; | |
font-family: "PT Mono"; | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>🌤 Weather API</h1> | |
<div id="weather" class="weather-temperature"></div> | |
<script> | |
function displayWeather(response) { | |
let weatherDiv = document.querySelector("#weather"); | |
let temperature = Math.round(response.data.main.temp); | |
let description = response.data.weather[0].description; | |
weatherDiv.innerHTML = `It is ${temperature} degrees, ${description}, in ${ | |
response.data.name | |
}`; | |
} | |
let city = "Rome"; | |
let key = "5f472b7acba333cd8a035ea85a0d4d4c"; | |
let url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${key}&units=metric`; | |
axios.get(url).then(displayWeather); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment