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

Scissors - Christian #63

Open
wants to merge 2 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
88 changes: 88 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>

Choose a reason for hiding this comment

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

Good, clear, semantic HTML. Nice work!

<html>
<head>
<title>Weather Report</title>




</head>
<body>
<div id="parent-container">
<div id="title-container">
<h1>
Weather Report
</h1>
<h4>
For the lovely city of
</h4>
<h2 id="city-container">
My Hometown
</h2>
</div>
<div id="cards-container">
<div id="column-1">
<div id="temperature-card">
<h2>
Temperature
</h2>
<div id="up-arrow">
⬆️
</div>
<div id="down-arrow">
⬇️
</div>
<div id="temperature-indicator" style="color: orange">
71
</div>
</div>
<div id="sky-card">
<h2>
Sky
</h2>
<select id="sky-type">
<option value="sunny">
Sunny
</option>
<option value="cloudy">
Cloudy
</option>
<option value="rainy">
Rainy
</option>
<option value="snowy">
snowy
</option>
</select>
</div>
<div id="city-name-card">
<h2>
City Name
</h2>
<input id="city-name-input" type="text" value="My Hometown">
<button id="reset-button">
Reset
</button>
</div>

</div>
<div id="column-2">
<h3>Weather Garden</h3>
<div id="landscape-card">
<p id="sky-landscape">
☁️ ☁️ ☁️ ☀️ ☁️ ☁️
</p>
<br>
<br>
<p id="ground-landscape">
🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷
</p>
</div>
</div>

</div>
</div>
<script src="./scripts/index.js"></script>
</body>

</html>
74 changes: 74 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const setIndicatorColor = (tag, value) => {
if (value >= 80) {
tag.style.color = "red";

Choose a reason for hiding this comment

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

Consider refactoring to assign a className, and then put the styles in the css file. For example:

#index.js
tag.className = “red”;

#styles.css
.red {
	color: red;
}

} else if ((value >= 70) && (value <= 79)) {
tag.style.color = "orange";
} else if ((value >= 60) && (value <= 69)) {
tag.style.color = "yellow";
} else if ((value >= 50) && (value <= 59)) {
tag.style.color = "green";
} else {
tag.style.color = "teal"
};
};

const setGroundLandscape = (tag, value) => {

Choose a reason for hiding this comment

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

Notice that setGroundLandscape and setIndicatorColor have a lot of the same code. Consider how you might write a single function that achieves both pieces of functionality.

if (value >= 80) {
tag.textContent = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂";
} else if ((value >= 70) && (value <= 79)) {

Choose a reason for hiding this comment

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

Minor note: the && is not necessary for this conditional test, we could just have:

Suggested change
} else if ((value >= 70) && (value <= 79)) {
} else if (value >= 70) {

tag.textContent = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷";
} else if ((value >= 60) && (value <= 69)) {
tag.textContent = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃";
} else {
tag.textContent = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
};
};

const setSkyLandscape = (tag, value) => {
if (value == "sunny") {
tag.textContent = "☁️ ☁️ ☁️ ☀️ ☁️ ☁️";
} else if (value == "cloudy") {
tag.textContent = "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️";
} else if (value == "rainy") {
tag.textContent = "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧 ";
} else if (value == "snowy") {
tag.textContent = "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨 ";
};
};

const changeSky = () => {
var sky = document.getElementById("sky-landscape");
var weather = document.getElementById("sky-type");
var value = weather.value;
setSkyLandscape(sky, value);
};

var skyType = document.getElementById("sky-type");
skyType.addEventListener("change", changeSky);

const increaseTemp = () => {
var indicator = document.getElementById("temperature-indicator");
var ground = document.getElementById("ground-landscape");
var temperature = parseInt(indicator.textContent);
//temperature++;
indicator.textContent = ++temperature;
setIndicatorColor(indicator, temperature);
setGroundLandscape(ground, temperature);
};

var upArrow = document.getElementById("up-arrow");
upArrow.addEventListener("click", increaseTemp, false);

const decreaseTemp = () => {
var indicator = document.getElementById("temperature-indicator");
var ground = document.getElementById("ground-landscape");
var temperature = parseInt(indicator.textContent);
//temperature = temperature - 1;
indicator.textContent = --temperature;
setIndicatorColor(indicator, temperature);
setGroundLandscape(ground, temperature);
};

var downArrow = document.getElementById("down-arrow");
downArrow.addEventListener("click", decreaseTemp, false);
Comment on lines +72 to +73

Choose a reason for hiding this comment

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

Consider moving all the Event Listener logic into a function called registerEventHandlers and add this code document.addEventListener("DOMContentLoaded", registerEventHandlers); to increase readability and changeability.