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

Cedar: Khandice Schuhmann #64

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
39 changes: 38 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,45 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
<link href="styles/index.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Abril+Fatface&display=swap" rel="stylesheet">
</head>
<body>

<header id="city_name_header">

Choose a reason for hiding this comment

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

Nice work writing semantic html

<h1 id="city_name">My Favorite City 😌</h1><br>
<h1 id="weather_report">Weather Report</h2>
</header>
<section id="weather_body">
<div id="sky_emojis">☁️ ☁️ ☁️ ☀️ ☁️ ☁️</div>
<div id="ground_emojis">🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲</div>
</section>
<section id="change_widgets">
<section id="change_temp">
<h4>Temp</h4>
<span id="temp_buttons">
<button id="raise_temp">🔼</button>
<button id="lower_temp">🔽</button>
</span>
<span id="temp_display"></span>
</section>
<section id="change_sky">
<h4>Sky</h4>
<select id="sky_dropdown">
<option id="dropdown_sunny" value="sunny">Sunny</option>
<option id="dropdown_cloudy" value="cloudy">Cloudy</option>
<option id="dropdown_rainy" value="rainy">Rainy</option>
<option id="dropdown_snowy" value="snowy">Snowy</option>
</select>
</section>
<section id="change_city">
<h4>City</h4>
<input type="text" id="user_input" placeholder="City Name" oninput="updateCity()" value="My Favorite City 😌"></input>
<button id="reset">Reset</button>
</section>
</section>
<script src="src/index.js" type="text/javascript"></script>
<footer>coded by Khandice Schuhmann &hearts;</footer>
</body>
</html>
127 changes: 127 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const updateCity = () => {
const userInput = document.querySelector('#user_input').value;
document.getElementById('city_name').innerHTML = userInput;
};

const createResetListener = () => {
const resetButton = document.getElementById('reset');
resetButton.addEventListener('click', function(){

Choose a reason for hiding this comment

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

For the callback functions in each of the addEventListener functions, consider encapsulating that functionality in a named function rather than an anonymous function to enhance readability.

document.getElementById('city_name').innerHTML = 'My Favorite City 😌';
})
};

const createSkyListener = () => {
document.getElementById('sky_dropdown').addEventListener('change', function() {
if (document.getElementById('sky_dropdown').value === "sunny"){
document.getElementById('sky_emojis').innerHTML = '☁️ ☁️ ☁️ ☀️ ☁️ ☁️';
}
if (document.getElementById('sky_dropdown').value === "cloudy"){
document.getElementById('sky_emojis').innerHTML =
'☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️';
}
console.log(document.getElementById('sky_dropdown').value);
if (document.getElementById('sky_dropdown').value === "rainy"){
document.getElementById('sky_emojis').innerHTML = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧';
}
console.log(document.getElementById('sky_dropdown').value);
if (document.getElementById('sky_dropdown').value === "snowy"){
document.getElementById('sky_emojis').innerHTML = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨';
}
});

};

const createTempListeners = () => {
const upArrow = document.querySelector("#raise_temp");
const downArrow = document.querySelector('#lower_temp');
const tempNum = document.getElementById('temp_display');
tempNum.innerHTML = 55;
upArrow.addEventListener("click", function(){
tempNum.innerHTML = parseInt(tempNum.innerHTML) + 1;
});
downArrow.addEventListener('click', function () {
tempNum.innerHTML = parseInt(tempNum.innerHTML) - 1;
});
};

city_name_header;
change_widgets;

Choose a reason for hiding this comment

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

It looks like these lines can be removed

const createGroundListener = () => {
document.getElementById('temp_display').addEventListener('DOMSubtreeModified', function () {
if (document.getElementById('temp_display').innerHTML <= 44) {

Choose a reason for hiding this comment

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

Nice work dynamically implementing these styles. It looks great!

Notice that there is quite a bit of repeated code here. Here are a couple ways you might consider refactoring. 1) Rather than applying the style directly to the element, you could assign a class to each element here, and then use that class to apply to styles. Assign each element that you are dynamically styling to a constant, and then you can use that constant to either directly change the style or assign a class name.

document.getElementById('ground_emojis').innerHTML = '🌲🎄🦭🦭🌲⛄️🌲🐻‍❄️⛄️🗻🐧🌲🎄';
document.getElementById('weather_body').style.backgroundColor =
'rgba(157, 236, 237, 0.701)';
document.getElementById('city_name_header').style.backgroundColor =
'rgba(157, 236, 237, 0.701)';
document.getElementById('change_temp').style.backgroundColor =
'rgba(157, 236, 237, 0.701)';
document.getElementById('change_sky').style.backgroundColor =
'rgba(157, 236, 237, 0.701)';
document.getElementById('change_city').style.backgroundColor =
'rgba(157, 236, 237, 0.701)';
}else if (document.getElementById('temp_display').innerHTML <= 59) {
document.getElementById('ground_emojis').innerHTML =
'🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲';
document.getElementById('weather_body').style.backgroundColor =
'rgba(99, 165, 235, 0.81)';
document.getElementById('city_name_header').style.backgroundColor =
'rgba(99, 165, 235, 0.81)';
document.getElementById('change_temp').style.backgroundColor =
'rgba(99, 165, 235, 0.81)';
document.getElementById('change_sky').style.backgroundColor =
'rgba(99, 165, 235, 0.81)';
document.getElementById('change_city').style.backgroundColor =
'rgba(99, 165, 235, 0.81)';
} else if (document.getElementById('temp_display').innerHTML <= 69) {
document.getElementById('ground_emojis').innerHTML =
'🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃';
document.getElementById('weather_body').style.backgroundColor =
'rgba(70, 184, 70, 0.701)';
document.getElementById('city_name_header').style.backgroundColor =
'rgba(70, 184, 70, 0.701)';
document.getElementById('change_temp').style.backgroundColor =
'rgba(70, 184, 70, 0.701)';
document.getElementById('change_sky').style.backgroundColor =
'rgba(70, 184, 70, 0.701)';
document.getElementById('change_city').style.backgroundColor =
'rgba(70, 184, 70, 0.701)';
} else if (document.getElementById('temp_display').innerHTML <= 79) {
document.getElementById('ground_emojis').innerHTML = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷';
document.getElementById('weather_body').style.backgroundColor =
'rgba(255, 234, 0, 0.701)';
document.getElementById('city_name_header').style.backgroundColor =
'rgba(255, 234, 0, 0.701)';
document.getElementById('change_temp').style.backgroundColor =
'rgba(255, 234, 0, 0.701)';
document.getElementById('change_sky').style.backgroundColor =
'rgba(255, 234, 0, 0.701)';
document.getElementById('change_city').style.backgroundColor =
'rgba(255, 234, 0, 0.701)';
}else if (document.getElementById('temp_display').innerHTML >= 80) {
document.getElementById('ground_emojis').innerHTML = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂';
document.getElementById('weather_body').style.backgroundColor =
'rgba(247, 153, 12, 0.701)';
document.getElementById('city_name_header').style.backgroundColor =
'rgba(247, 153, 12, 0.701)';
document.getElementById('change_temp').style.backgroundColor =
'rgba(247, 153, 12, 0.701)';
document.getElementById('change_sky').style.backgroundColor =
'rgba(247, 153, 12, 0.701)';
document.getElementById('change_city').style.backgroundColor =
'rgba(247, 153, 12, 0.701)';
}
});
};


const registerEventHandlers = () => {
createSkyListener();
updateCity();
createResetListener();
createTempListeners();
createGroundListener();
};

// wait to register my event handlers until page is fully loaded.
document.addEventListener("DOMContentLoaded", registerEventHandlers);
88 changes: 88 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
body {
background-color: rgba(141, 187, 235, 0.742);
}
header, #weather_body, #change_temp, #change_sky, #change_city{
background-color: rgba(99, 165, 235, 0.81);
color: white;
font-family: 'Abril Fatface', cursive;
}

#city_name_header {
display: flex;
justify-content: center;
margin: 50px 575px;
border-radius: 50px;
padding: 0px 15px;
font-size: smaller;
}

#weather_body {
margin: 35px 175px;
border-radius: 5px;
font-size: 5em;
text-align: center;
}

#weather_body div {
padding: 50px 0px;
}
#change_widgets {
display: flex;
margin: 35px 250px;
justify-content: space-between;
}

#change_temp, #change_sky, #change_city {
border-radius: 50%;
text-align: center;
width: 200px;
height: 175px;
font-size: 25px;

}

#change_temp{
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 2fr;
}

#change_temp h4 {
grid-row-start: 1;
grid-column: 1 / span 2;
}
/* #lower_temp {
grid-row-start: 2;
grid-column-start: 1;
}

#temp_display {
grid-column-start: 2;
grid-column-end: 3;
grid-row: 1 / span 2;

} */

#temp_buttons {
margin: -20px;
}

#temp_buttons button {
width: 20px;
border: none;
display: block;
align-self: end;
}

#sky_dropdown {
width: 150px;
}

#reset {
border-radius: 5px;
font-family: 'Abril Fatface', cursive;
}

footer{
text-align: center;
}