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 - Katrina K #62

Open
wants to merge 5 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/wireFrame.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>TheWeather</title>
<link href="styles/index.css" rel="stylesheet">
</head>
<body>
<header>
<h1>And now for <em>The Weather...</em></h1>
<h2 id="currentCity">Currently in ✨Seattle✨</h2>
</header>

<main class="displayGroup">
<section id="tempPicker" class="adjuster">
<section>
<button id="tempIncreaseButton">^</button>
<button id="tempDecreaseButton">v</button>
</section>
<section id="tempDisplay">73</section>
</section>
<section id="cloudDisplay" class="adjuster">
<select name="howCloudy" id="cloudStatus">
<option value="cloudy">Cloudy</option>
<option value="partlyCloudy">Partly Cloudy</option>
<option value="rainy">Rainy</option>
<option value="sunny">Sunny</option>
<option value="onFireSky">This is fine.</option>
</select>
</section>
<section id="citySetter" class="adjuster">
<section id="cityDisplay">Seattle</section>
<section>
<label for="cityPicker">Enter a new city:</label>
<input type="text" id="cityPicker" name="name">
</section>
<section>
<button id="resetCity">Reset</button>
</section>
</section>
<div class="break"></div>
<section id="gardenDisplay">
Weather Garden
<section id="sky">☁️__☀️☁️_☁️</section>
<section id="landscape">🌻__🌷🌷🌱_</section>
<iframe src="https://open.spotify.com/embed/playlist/7rYLGI2WpU0wPKQo4DKbpK" width="100%" height="80" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>
</section>
</main>

<script src="scripts/index.js" type="text/javascript"></script>
</body>
</html>
88 changes: 88 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const state = {
temp: 73,
cloudy: "☁️☁️☁️_☁️☁️☁️☁️☁️☁️",
partlyCloudy: "☁️☁️___☀️☁️_☁️☁️",
rainy: "🌧🌧🌧🌧🌧🌧🌧🌧🌧🌧",
sunny: "___☀️☁️_____",
onFireSky: "☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️",
onFireGround: "🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥",
garden: "🌻__🌷🌷🌱_",
}

const emojiSelector = {
0: "✨",
1: "⚡️",
2: "👾",
3: "⭐️",
4: "🌈",
}

const randEmoji = () => {
return emojiSelector[Math.floor(Math.random() * 5)];
}
Comment on lines +20 to +22

Choose a reason for hiding this comment

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

Neat!


const changeTemp = (delta) => {
state.temp += delta;
const tempDisplay = document.querySelector("#tempDisplay");
tempDisplay.textContent = `${state.temp}`;
}
Comment on lines +24 to +28

Choose a reason for hiding this comment

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

Great helper function!

How could you add in the text color change here?


const increaseTemp = () => {
changeTemp(1);
}

const decreaseTemp = () => {
changeTemp(-1);
}

const skyDisplayUpdate = () => {
const updatedWeather = document.getElementById("cloudStatus").value;
const skyDisplay = document.getElementById("sky");
skyDisplay.textContent = state[updatedWeather];
if (updatedWeather === "onFireSky") {
document.getElementById("landscape").textContent = state.onFireGround;
}
else {
document.getElementById("landscape").textContent = state.garden;
}
}

const cityReset = () => {
const cityDisplayCard = document.getElementById("cityDisplay");
const cityTitleDisplay = document.getElementById("currentCity");

let frameEmoji = randEmoji();

cityDisplayCard.textContent = "Seattle";
cityTitleDisplay.textContent = "Currently in " + frameEmoji + "Seattle" + frameEmoji;
}

const cityUpdate = () => {
const newCity = document.getElementById("cityPicker").value;
const cityDisplayCard = document.getElementById("cityDisplay");
const cityTitleDisplay = document.getElementById("currentCity");

let frameEmoji = randEmoji();

cityDisplayCard.textContent = newCity;
cityTitleDisplay.textContent = "Currently in " + frameEmoji + newCity + frameEmoji;
}

const registerEventHandlers = () => {
const increaseButton = document.querySelector("#tempIncreaseButton");
increaseButton.addEventListener("click", increaseTemp);

const decreaseButton = document.querySelector("#tempDecreaseButton");
decreaseButton.addEventListener("click", decreaseTemp);

const changeWeather = document.getElementById("cloudStatus");
changeWeather.addEventListener("change", skyDisplayUpdate);

const updateCity = document.getElementById("cityPicker");
updateCity.addEventListener("change", cityUpdate);
Comment on lines +81 to +82

Choose a reason for hiding this comment

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

This works, but there are multiple event types that can be used here that result in different behavior. The change event doesn't trigger unless user presses enter, while the input event will trigger every time the user inputs a character (https://www.w3schools.com/jsref/event_oninput.asp).


const resetCity = document.getElementById("resetCity");
resetCity.addEventListener("click", cityReset);
}

document.addEventListener("DOMContentLoaded", registerEventHandlers);
44 changes: 44 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
html, body {
height: 95%;
background-color: skyblue;
}

* {
border-color: black;
border-width: 2px;
border-style: dashed;
}

main {
display: flex;
border: 1px solid hotpink;
flex-flow: column wrap;
justify-content: space-around;
align-items: flex-start;
}
section {
padding: 20px;
border-radius: 4px;
}

.adjuster {
flex: 1 1 33%;
text-align: center;
}

.break {
flex-basis: 100%;
}

#gardenDisplay {
/* height: auto;
width: auto; */
}

#tempDisplay {
font-size: 50px;
}

button:hover {
border: 2px solid yellow;
}