-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display current day, time and temperature of searched city
- Loading branch information
0 parents
commit a547bf7
Showing
3 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!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" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" | ||
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" | ||
crossorigin="anonymous" | ||
/> | ||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<title>Weather App</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="weather-app"> | ||
<form class="search-form" id="search-form"> | ||
<div class="row"> | ||
<div class="col-9"> | ||
<input | ||
type="search" | ||
placeholder="Type a city.." | ||
autofocus="on" | ||
autocomplete="off" | ||
id="city-input" | ||
class="form-control shadow-sm" | ||
/> | ||
</div> | ||
<div class="col-3"> | ||
<input | ||
type="submit" | ||
value="Search" | ||
class="form-control btn btn-primary shadow-sm" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
<h1 id="city"> | ||
Sydney NSW, Australia | ||
</h1> | ||
<ul> | ||
<li id="date"></li> | ||
<li> | ||
Partly Cloudy | ||
</li> | ||
</ul> | ||
<div class="row"> | ||
<div class="col-6"> | ||
<div class="clearfix"> | ||
<img | ||
src="https://ssl.gstatic.com/onebox/weather/64/partly_cloudy.png" | ||
alt="Cloudy icon" | ||
class="weather-icon float-left" | ||
/> | ||
<div class="float-left"> | ||
<span class="temperature" id="temperature">19</span | ||
><span class="units"> | ||
<a href="#" id="celsius-link">°C</a> | | ||
<a href="#" id="fahrenheit-link">°F</a> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-6"> | ||
<ul> | ||
<li> | ||
Precipitation: 0% | ||
</li> | ||
<li> | ||
Humidity: 77% | ||
</li> | ||
<li> | ||
Wind: 8 km/h | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
function formatDate(date) { | ||
let hours = date.getHours(); | ||
if (hours < 10) { | ||
hours = `0${hours}`; | ||
} | ||
let minutes = date.getMinutes(); | ||
if (minutes < 10) { | ||
minutes = `0${minutes}`; | ||
} | ||
|
||
let dayIndex = date.getDay(); | ||
let days = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
let day = days[dayIndex]; | ||
|
||
return `${day} ${hours}:${minutes}`; | ||
} | ||
|
||
function search(event) { | ||
event.preventDefault(); | ||
let cityElement = document.querySelector("#city"); | ||
let cityInput = document.querySelector("#city-input"); | ||
cityElement.innerHTML = cityInput.value; | ||
} | ||
|
||
function convertToFahrenheit(event) { | ||
event.preventDefault(); | ||
let temperatureElement = document.querySelector("#temperature"); | ||
temperatureElement.innerHTML = 66; | ||
} | ||
|
||
function convertToCelsius(event) { | ||
event.preventDefault(); | ||
let temperatureElement = document.querySelector("#temperature"); | ||
temperatureElement.innerHTML = 19; | ||
} | ||
|
||
// Feature #1 | ||
let dateElement = document.querySelector("#date"); | ||
let currentTime = new Date(); | ||
dateElement.innerHTML = formatDate(currentTime); | ||
|
||
// Feature #2 | ||
let searchForm = document.querySelector("#search-form"); | ||
searchForm.addEventListener("submit", search); | ||
|
||
// Bonus Feature | ||
let fahrenheitLink = document.querySelector("#fahrenheit-link"); | ||
fahrenheitLink.addEventListener("click", convertToFahrenheit); | ||
|
||
let celsiusLink = document.querySelector("#celsius-link"); | ||
celsiusLink.addEventListener("click", convertToCelsius); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
body { | ||
font-family: arial, sans-serif; | ||
} | ||
|
||
h1 { | ||
color: #7c7c7c; | ||
font-size: 24px; | ||
font-weight: 100; | ||
line-height: 28px; | ||
margin: 0; | ||
} | ||
|
||
ul { | ||
margin: 0 0 10px; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
color: #7c7c7c; | ||
font-size: 16px; | ||
font-weight: 100; | ||
height: 19px; | ||
line-height: 1; | ||
list-style: none; | ||
} | ||
|
||
.weather-app { | ||
border: 1px solid #dadde1; | ||
padding: 15px; | ||
margin: 20px auto; | ||
border-radius: 10px; | ||
max-width: 600px; | ||
} | ||
|
||
.weather-icon { | ||
height: 64px; | ||
width: 64px; | ||
margin-right: 10px; | ||
} | ||
|
||
.temperature { | ||
color: rgb(33, 33, 33); | ||
font-size: 64px; | ||
font-weight: 400; | ||
line-height: 1; | ||
} | ||
|
||
.units { | ||
position: relative; | ||
top: -34px; | ||
} | ||
|
||
.search-form { | ||
margin-bottom: 20px; | ||
} |