Skip to content

Instantly share code, notes, and snippets.

@yhaskell
Created March 9, 2019 08:02
Show Gist options
  • Save yhaskell/1ff5088e7f862b077fd065225c234e81 to your computer and use it in GitHub Desktop.
Save yhaskell/1ff5088e7f862b077fd065225c234e81 to your computer and use it in GitHub Desktop.
weather in London
<!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">
<title>Weather in London</title>
</head>
<body>
<p>Current weather in London:</p>
<script>
const token = 'xxxxx';
const id = 2643743;
fetch(`http://api.openweathermap.org/data/2.5/weather?id=${id}&units=metric&APPID=${token}`)
.then(data => data.json())
.then((data) => {
const div = document.createElement('div');
div.innerHTML = `${data.weather.map(w => w.description).join(', ')}, ${data.main.temp.toFixed(0)}ºC`;
document.body.appendChild(div);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment