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

Melinda H. Pine Class #77

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
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 lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./styles/index.css" />
<title>Document</title>
</head>

<body>
<header>
<div class="head-title"> Weather Report</div>
<p>For the lovely city of <span id="city-display">Honolulu</span></p>
</header>
<main>
<section id="Temperature">
<h2> Temperature </h2>
<button id="up-arrow">⬆️</button>
<button id="down-arrow">⬇️</button>
<div id="temperature-number" class="color"></div>
</section>

<section id="Sky-Container">
<h3> Sky </h3>

Choose a reason for hiding this comment

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

This section is a sibling of the temperature section, so the h-tag level would be the same.

Suggested change
<h3> Sky </h3>
<h2> Sky </h2>

<select id="sky">
<option value="Sunny">Sunny</option>
<option value="Cloudy">Cloudy</option>
<option value="Rainy">Rainy</option>
<option value="Snowy">Snowy</option>
</select>
</section>

<section id="Weather-Garden">
<h4> Weather Garden</h4>

Choose a reason for hiding this comment

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

Suggested change
<h4> Weather Garden</h4>
<h2> Weather Garden</h2>

<div id ="selected-weather"></div>
</section>


<section id="City-Name">
<h3> City Name </h3>

Choose a reason for hiding this comment

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

Suggested change
<h3> City Name </h3>
<h2> City Name </h2>

<input type="text" id="city">
</section>
</main>
<script src="scripts/index.js" type="text/javascript"></script>
</body>

</html>
105 changes: 105 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// connect the up arrow so id of up-arrow to an on click event
// when the id is clicked, then increase temp counter by 1

// temperature variable, every time the user clickes the button, the temperature count goes up by 1


// const appearanceHeading = document.getElementById("facts__heading");

// appearanceHeading.textContent = "Qualities and Traits of a Crab";
let temperature = 80


const increaseTemp=()=> {
// When clicked the temperature will rise by 1 degree
++temperature
// console.log("i am clicking the up button")
// console.log(temperature)
document.getElementById("temperature-number").innerHTML=temperature
// console.log('I am the color', color)
}


const decreaseTemp=()=> {
// When clicked the temperature will drop by 1 degree
--temperature
console.log("i am clicking the down button")
console.log(temperature)
document.getElementById("temperature-number").innerHTML=temperature
console.log(color)
}

// New Function will change the sky in Weather Garden
// based on the selected sky in the drop down menu
const setTypeOfWeather=()=> {
let skyValue = document.getElementById("sky").value
let sky = document.getElementById("selected-weather")

// if skyValue == "Sunny"
// set sky innerHtml to a sun
if (skyValue=="Sunny") {
sky.innerHTML="☁️ ☁️ ☁️ ☀️ ☁️ ☁️";
} else if (skyValue=="Cloudy") {
sky.innerHTML="☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️";
} else if (skyValue=="Rainy") {
sky.innerHTML="🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧";
} else if (skyValue=="Snowy") {
sky.innerHTML="🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨";
};
console.log(skyValue)
}
setTypeOfWeather()

Choose a reason for hiding this comment

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

I recommend moving this call inside the 'registerEventHandlers' function, so that it's guaranteed to run after the html is loaded.


const setCityName=()=> {
let cityValue= document.getElementById("city").value
let sky = document.getElementById("city-display")
sky.textContent = cityValue
}


const registerEventHandlers = () => {
// Get up arrow HTML element by ID
const upArrowButton = document.querySelector("#up-arrow");

// Add Click event listener to up arrow button
// "click" -> event type
// increaseTemp -> function that gets called
upArrowButton.addEventListener("click", increaseTemp);

const downArrowButton = document.querySelector("#down-arrow");

downArrowButton.addEventListener("click", decreaseTemp);

// when sky dropdown changes (onChange)
// call setTypeOfWeather()
const skyDropdown = document.querySelector("#sky");
skyDropdown.addEventListener("change", setTypeOfWeather);

const cityInputText = document.querySelector("#city");
cityInputText.addEventListener("input", setCityName);
};

document.addEventListener("DOMContentLoaded", registerEventHandlers);



// document.getElementById('output').innerHTML = lengthOfName;
document.getElementById("temperature-number").innerHTML=temperature

// range for color and landscape icons

let color = '';

if (temperature >=80) {
color = 'red'
} else if (70<=temperature<=79) {

Choose a reason for hiding this comment

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

I know this section isn't running right now, but I wanted to point out a syntax issue. This type of conditional has to be formatted like this:

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

the && is equivalent to and in python.

color = 'orange'
} else if (60<=temperature<=69) {
color = 'yellow'
}else if (50<=temperature<=59) {
color = 'green'
}else if (49<=temperature) {
color = 'teal'
}

document.getElementsByClassName("color").innerHTML=color
10 changes: 10 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* {
background-color: rgb(140, 137, 155);
}


.head-title {
background-color: rgb(150, 10, 10);

}