Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper - Kate Malakhova #59

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
Binary file added assets/mostlysunny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>Weather Report</title>
<meta charset="UTF-8">
<link href="styles/index.css" rel="stylesheet"/>
</head>
<body>
<header class="header">
<img src="assets/mostlysunny.png" alt="Weather Conditions">
<h1>Weather Report</h1>
<h3>For the lovely city of ✨<span id=headerCity>NEVERLAND</span>✨</h3>
</header>
<body>
<section class="temperature-section">
<h2>Temperature (F)</h2>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fahrenheit? Sigh, no one here uses rational measurements. (not serious)

<div id=temperature-content>
<div id="up-down-arrows">
<p><button id="increase-temp">⬆</button></p>
<p><button id="decrease-temp">⬇</button></p>
</div>
<p>&nbsp;</p><span id="currentTemp">65</span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would start off the span here with the default class value for 65 degrees.

</div>
</section>
<section class="sky-section">
<h2>Sky</h2>
<select id="sky-options">
<option>--Select--</option>
<option>Sunny</option>
<option>Cloudy</option>
<option>Rainy</option>
<option>Snowy</option>
</select>
</section>
<section class="city-section">
<h2>City</h2>
<input type="text" id="cityInput" placeholder = "Type your city name">
<button id="reset-button">RESET</button>
</section>
<section class="weather-section">
<br><h1>☀️ Your Weather Forecast 🌧️</h1>
<div id="weather-content">
<div id="sky"></div>
<div id="ground"></div>
</div>
</section>
<script src="scripts/index.js"></script>
</body>
</html>
103 changes: 103 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
let currentTemp = 65;

const updateTempColor = currentTemp => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good helper function

const tempContainer = document.getElementById("currentTemp");
let color = "green";
if (currentTemp >= 80) {
color = "red";
} else if (currentTemp >= 70) {
color = "orange";
} else if (currentTemp >= 60) {
color = "yellow";
} else if (currentTemp >= 50) {
color = "green";
} else if (currentTemp < 50) {
color = "teal";
}
tempContainer.classList = color;
};

const updateTemp = currentTemp => {
const tempContainer = document.getElementById("currentTemp");
tempContainer.textContent = currentTemp;
updateTempColor(currentTemp);
updateLandscape(currentTemp);
};

const increaseTemp = () => {
currentTemp += 1;
updateTemp(currentTemp);
};

const decreaseTemp = () => {
currentTemp -= 1;
updateTemp(currentTemp);
};
Comment on lines +27 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that you can combine these functions with:

Suggested change
const increaseTemp = () => {
currentTemp += 1;
updateTemp(currentTemp);
};
const decreaseTemp = () => {
currentTemp -= 1;
updateTemp(currentTemp);
};
const changeTemp = (increment) => {
currentTemp += increment;
updateTemp(currentTemp);
};

Then we can register the event handler with an anonymous function like this:

increaseTempButton.addEventListener("click", () => updateTemp( +1 ) );


const updateSky = () => {
const skyOption = document.getElementById("sky-options").value;
const skyContainer = document.getElementById("sky");
let sky = "";
if (skyOption === "Sunny") {
sky = "☁️☁️☁️☁️☁️☀️☁️☁️☁️☁️☁️";
skyColor = "sunny";
} else if (skyOption === "Cloudy") {
sky = "☁️☁️☁️☁️☁️⛅☁️☁️☁️☁️☁️";
skyColor = "cloudy";
} else if (skyOption === "Rainy") {
sky = "🌧🌧🌧🌧🌧🌦🌧🌧🌧🌧🌧";
skyColor = "rainy";
} else if (skyOption === "Snowy") {
sky = "🌨❄️🌨❄️🌨❄️🌨❄️🌨❄️🌨";
skyColor = "snowy";
}
skyContainer.textContent = sky;
};

const updateLandscape = (currentTemp) => {
const groundContainer = document.getElementById("ground");
let ground = "";
if (currentTemp >= 80) {
ground = "🌵🐍🦂🌵🐍🦂🌵🐍🦂🌵🐍";
} else if (currentTemp >= 70) {
ground = "🌸🌿🌼🌿🌸🌿🌼🌿🌸🌿🌼";
} else if (currentTemp >= 60) {
ground = "🌾🍃🌾🍃🌾🍃🌾🍃🌾🍃🌾";
} else if (currentTemp >= 50){
ground = "🍂🍁🍂🍁🍂🍁🍂🍁🍂🍁🍂"
} else if (currentTemp < 50){
ground = "🌲🌲⛄️🌲🌲⛄️🌲🌲⛄️🌲🌲"
}
groundContainer.textContent = ground;
};

const updateCity = () => {
const inputCity = document.getElementById("cityInput").value;
const headerCity = document.getElementById("headerCity");
headerCity.textContent = inputCity;
};

const resetCity = () => {
const cityNameInput = document.getElementById("cityInput");
cityNameInput.value = "Neverland";
updateCity();
};

const registerEventHandlers = () => {
const increaseTempButton = document.getElementById("increase-temp");
increaseTempButton.addEventListener("click", increaseTemp);

const decreaseTempButton = document.getElementById("decrease-temp");
decreaseTempButton.addEventListener("click", decreaseTemp);

const skyOption = document.getElementById("sky-options");
skyOption.addEventListener("change", updateSky);

const inputCity = document.getElementById("cityInput");
inputCity.addEventListener("input", updateCity);

const resetCityButton = document.getElementById("reset-button");
resetCityButton.addEventListener("click", resetCity);
};

document.addEventListener("DOMContentLoaded", registerEventHandlers);
160 changes: 160 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
body {
display: grid;
grid-template-columns: 1fr 2fr;
background: #add8e6;
grid-gap: 15px;
margin-left: 50px;
margin-right: 50px;
}

.header {
display: flex;
align-items: center;
grid-column: span 3;
/* width: 100%; */
font-size: 80px;
justify-content: space-around;
}

.header img {
height: 100px;
}

h1, h3 {
color:whitesmoke;
font-family: 'Open Sans Condensed', sans-serif;
font-size: 50px;
font-weight: 700;
line-height: 64px;
text-align: center;
text-transform: uppercase;
}

h2 {
color: rgb(39, 39, 39);
font-family: 'Open Sans', sans-serif;
font-size: 30px;
font-weight:500;
text-align: center;
background-color: rgba(255, 238, 140, 0.041);
}

h3 {
font-size: 25px;
font-weight:lighter;
}

.sky-section,
.city-section {
text-align: center;
}

button {
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
background-color:#ededed;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
cursor:pointer;
color:#575757;
font-family:Arial;
font-size:13px;
padding:6px 10px;
}

button:hover {
background:linear-gradient(to bottom, #dfdfdf 5%, #ededed 100%);
background-color:#dfdfdf;
}

button:active {
position:relative;
top:1px;
}

.temperature-section,
.sky-section,
.city-section {
border-radius: 10px;
padding: 10px;
background-color: #d6ecf3;
}

.weather-section {
border-radius: 10px;
padding: 10px;
background-color: #eff7fa;
text-align: center;
}

.weather-section h1 {
text-transform: uppercase;
font-weight: bolder;
color: rgb(71, 71, 71);
font-size: 40px;
}

.weather-section h1:before,
.weather-section h1:after{
position: relative;
content: "";
width: 30%;
left: 35%;
display: block;
margin-bottom: 10px;
margin-top: 10px;
border-bottom: 5px dotted rgb(255, 255, 255);
}

.temperature-section {
grid-row: 2;
}
.weather-section {
grid-row: 2 / span 3;
}

.sky-section {
grid-row: 3;
}
.city-section {
grid-row: 4;
}

#temperature-content {
display: flex;
flex-direction: row;
justify-content: center;
}

#currentTemp {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
font-size: 60px;
font-family: 'Baloo Bhai', 'Source Sans Pro', sans-serif;
font-weight: 900;
}

.red {
color: red;
}
.orange {
color: rgba(255, 68, 0, 0.794);
}
.yellow {
color: rgb(255, 196, 0);
}
.green {
color: green;
}
.teal {
color: rgba(70, 148, 194, 0.753);
}

#sky,
#ground {
font-size: 50px;
line-height: 80px;
}