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

gloria/scissors #71

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions assets/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂
61 changes: 61 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html>
<head>
<Title>Weather Report</Title>
<link rel="stylesheet" href="styles/index.css">


</head>
<body>
<div>
<div id="header">
<h1>Weather Report</h1>
<span>For the lovely city of </span>
<h3 id="town-name">My Hometown</h3>
</div>
<div id="content">
<div id="temperature-card">
<h3 id="temperature-title">Temperature</h3>
<br>
<div id="up-arrow" onclick="increaseTemperature()">⬆️</div>
<div id="decreaseTempArrow">⬇️</div>
Comment on lines +20 to +21

Choose a reason for hiding this comment

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

These arrows are buttons! It is best practice to use semantic HTML and make these button elements.

In addition, rather than putting the onclick event right into the html, we encourage you to use javascript to do this and add the event listener the same way you did for decreaseTemperature

Suggested change
<div id="up-arrow" onclick="increaseTemperature()">⬆️</div>
<div id="decreaseTempArrow">⬇️</div>
<button id="up-arrow" onclick="increaseTemperature()">⬆️</button>
<button id="decreaseTempArrow">⬇️</button>

<div>
<span class="orange-temp" id="temp-value">71</span>
</div>


</div>
<div id="sky-card">
<h3>Sky</h3>
<br>
<select name="sky">
<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-card">
<h3>City Name</h3>
<br>
<input type="text" value="My Hometown">
<button="resetButton">Reset</button>
</div>
<div id="garden-card">
<h3>Weather Garden</h3>
<br>
<div>
<p id="sky-landscape">☁️ ☁️ ☁️ ☀️ ☁️ ☁️ </p>
<br>
<br>
<br>
<p id="ground-landscape">🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷</p>
</div>

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

109 changes: 109 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@


const tempToColor = (temp) => {

Choose a reason for hiding this comment

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

Notice that tempToColor and tempToLandscape have similar logic. Consider how you might combine these two functions to DRY up your code.

if (temp >= 80){
return "red-temp";
} else if (temp >= 70){
return "orange-temp";
} else if (temp >= 60){
return "yellow-temp";
} else if (temp >= 50){
return "green-temp";
} else {
return "teal-temp";
}
// ((temp>= 70) && (temp <= 79))
};

const tempToLandscape = (temp) => {
if (temp >= 80){
return "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂"
} else if (temp >= 70){
return "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷"
} else if (temp >= 60){
return "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃"
} else {
return "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲"
}
};

const skyToLandscape = (sky) => {

Choose a reason for hiding this comment

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

I like how you encapsulated this logic in a function that returns the value that you need, and then you can invoke the function and use the return value in the event handler.

if (sky == "sunny"){
return "☁️ ☁️ ☁️ ☀️ ☁️ ☁"
} else if (sky == "cloudy"){
return "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️"
} else if (sky == "rainy"){
return "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧"
} else if (sky == "snowy"){
return "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨"
}
}

const resetClickCount = ()=>{
StaticRange.clickCount = 0;
const townnameContainer = document.getElementBy("town-name");
};

const setTempClass = (tag, className) => {

Choose a reason for hiding this comment

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

Clever! An alternative to removing all the classes we don't need, and adding the class we do need is using this attribute tag.className = "red-temp"

tag.classList.remove("red-temp");
tag.classList.remove("orange-temp");
tag.classList.remove("yellow-temp");
tag.classList.remove("green-temp");
tag.classList.remove("teal-temp");
//remove all the classes
tag.classList.add(className);
};

const setGroundLandscape = (temp) => {
let p = document.getElementById("ground-landscape");
let groundValue = tempToLandscape(temp);
p.innerText = groundValue;
};


const increaseTemperature = function(){
let span=document.getElementById("temp-value");
let value = parseInt(span.innerText);
value +=1; //convert from string to int
span.innerText = value;
let className=tempToColor(value);
setTempClass(span,className);
setGroundLandscape(value);
};




const decreaseTemp = () => {
const span = document.querySelector("#temp-value");
let value = parseInt(span.textContent);
value -=1;
span.textContent = value;
let className=tempToColor(value);
setTempClass(span,className);
setGroundLandscape(value);
};

const changeSky = () => {

let p = document.getElementById("sky-landscape");
let select = document.querySelector("#sky-card > select"); //select is tag
let weather = select.value;
let landscape = skyToLandscape(weather);
p.textContent = landscape;

// use sky to landscape function select.value
// let className=tempToColor(value);
// skyToLandscape = select.value
}
const decreaseTempArrow = document.querySelector("#decreaseTempArrow"); //# is id
decreaseTempArrow.addEventListener('click',decreaseTemp);
let select = document.querySelector("#sky-card > select"); //select is tag
select.addEventListener('change',changeSky);
Comment on lines +99 to +102

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.








33 changes: 33 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#select by class
.orange-temp {
color: orange;
}

.red-temp {
color: red;
}

.yellow-temp {
color: yellow;
}

.green-temp {
color: green;
}

.teal-temp {
color: teal;
}

#city-card input {
background-color: red
}

#city-card > h3 {
margin: 20px;
}