Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions weather/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
Binary file added weather/Weather.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions weather/weather.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

body{
font-family: 'montserrat', sans-serif;
background-image: url('Weather.jpg');
background-size: cover;
background-position: top center;
}

.app-wrap{
display: flex;
flex-direction: column;
min-height: 100vh;
background-image: linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(0,0,0,0.6));
}

header{
display: flex;
justify-content: center;
align-items: center;
padding: 50px 15px 15px;
}

header input{
width: 100%;
max-width: 280px;
padding: 10px 15px;
border: none;
outline: none;
background-color: rgba(255,255,255, 0.3);
border-radius: 16px 0px 16px 0px;
border-bottom: 3px solid orange;

color: lightgray;
font-size: 20px;
font-weight: 300;
transition: 0.2s ease-out;
}

header input:focus{
background-color: rgba(255,255,255,0.6);
}

main {
flex: 1 1 100%;
padding: 25px 25px 50px;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}

.location .city{
color: lightcyan;
font-size: 32px;
font-weight: 500;
margin-bottom: 5px;
}

.location .date{
color: lightcyan;
font-size: 16px;
}

.current .temp{
color: lightcyan;
font-size: 102px;
font-weight: 900;
margin: 30px 0px;
text-shadow: 2px 10px rgba(0,0,0,0.75);
}

.current .temp span{
font-weight: 500;
}

.current .weather{
color: lightcyan;
font-size: 32px;
font-weight: 700;
font-style: italic;
margin-bottom: 15px;
text-shadow: 0px 3px rgba(0,0,0,0.4);
}

.current .hi-low{
color: lightcyan;
font-size: 24px;
font-weight: 500;
text-shadow: 0px 4px rgba(0,0,0,0.4);
}

29 changes: 29 additions & 0 deletions weather/weather.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather</title>
<link rel="stylesheet" href="weather.css">
</head>
<body>
<div class="app-wrap">
<header>
<input type="text" autocomplete="off" class="search-box"
placeholder="Search for a city...">
</header>
<main>
<section class="location">
<div class="city">Jericho, NY</div>
<div class="date">Wednesday 3 September 2020</div>
</section>
<div class="current">
<div class="temp">15<span>°c</span></div>
<div class="weather">Sunny</div>
<div class="hi-low">13°c / 16°c</div>
</div>
</main>
</div>
<script src="weather.js"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions weather/weather.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const api = {
key: "53d5ab9baedfa34cf3599c8db30a3b2c",
base: "https://api.openweathermap.org/data/2.5/"
}

const searchbox = document.querySelector('.search-box');
searchbox.addEventListener('keypress',setQuery);

function setQuery(evt){
if(evt.keyCode == 13){
getResults(searchbox.value);
console.log(searchbox.value);
}
}

function getResults (query) {
fetch(`${api.base}weather?q=${query}&units=metric&APPID=${api.key}`)
.then(weather => {
return weather.json();
}).then(displayResults);
}

function displayResults(weather){
console.log(weather);
let city = document.querySelector('.location .city');
city.innerText = `${weather.name}, ${weather.sys.country}`;

let now = new Date();
let date = document.querySelector('.location .date');
date.innerText = dateBuilder(now);

let temp = document.querySelector('.current .temp');
temp.innerHTML = `${Math.round(weather.main.temp)}<span>°c</span>`;

let weather_el = document.querySelector('.current .weather');
weather_el.innerText = weather.weather[0].main;

let hilow = document.querySelector('.hi-low');
hilow.innerText = `${weather.main.temp_min}°c / ${weather.main.temp_max}°c`;
}

function dateBuilder(d) {
let months = ["January", "Feburary", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thrusday", "Friday", "Saturday"];

let day = days[d.getDay()];
let date = d.getDate();
let month = months[d.getMonth()];
let year = d.getFullYear();

return `${day} ${date} ${month} ${year}`;
}