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

Amethyst: Megan & Jay #61

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
345754d
html structure
scrambledmegs Jun 8, 2023
636c0bc
created html content
scrambledmegs Jun 8, 2023
598ec2d
working on wave 02
jayriverking Jun 8, 2023
05989c1
using innerText
jayriverking Jun 8, 2023
aab2cf8
add comments
jayriverking Jun 8, 2023
57648ca
adds functionality to up and down buttons to change temp
scrambledmegs Jun 8, 2023
cf1d3b8
adds functionality to up and down buttons to change temp
scrambledmegs Jun 8, 2023
25f74a0
add color change for temp up & down buttons
jayriverking Jun 8, 2023
d7d7b6e
Mikelle's presence solved the issue
jayriverking Jun 8, 2023
7654346
got rid of numInt inside colorTemp
jayriverking Jun 8, 2023
f51af66
adds weather garden container
scrambledmegs Jun 8, 2023
b68afa9
adds weather garden style
scrambledmegs Jun 8, 2023
e58c9ae
Merge branch 'main' of https://github.com/scrambledmegs/weather-report
scrambledmegs Jun 8, 2023
0495580
adds background color change to weather garden
scrambledmegs Jun 8, 2023
6454f4f
adds weather emojis on temperature change
scrambledmegs Jun 8, 2023
1d8df3f
adds weather emojis to html
scrambledmegs Jun 8, 2023
c8fefdb
finished wave03
jayriverking Jun 8, 2023
83f9439
worked on wave 04
jayriverking Jun 12, 2023
b88683b
wave 04 almost done just need to convert kevin to farenheit
jayriverking Jun 12, 2023
d4eecf0
mostly all working
jayriverking Jun 12, 2023
6389dc3
done working on wave 04
jayriverking Jun 12, 2023
516c607
very small refactor
jayriverking Jun 12, 2023
78ba8af
refactored drop down menu and added element for sky emojis
scrambledmegs Jun 12, 2023
9ff58be
function to change sky emojis based on dropdown menu choice
scrambledmegs Jun 12, 2023
f71583d
modified element id in const skyEmojis
scrambledmegs Jun 13, 2023
3462121
implemented state (ish)
jayriverking Jun 13, 2023
92a3fbd
add on load functionality
jayriverking Jun 13, 2023
a4a4a80
merge1
jayriverking Jun 13, 2023
d00f860
refactored html
scrambledmegs Jun 13, 2023
e35ae5c
updated js
scrambledmegs Jun 13, 2023
c3ec424
created styles
scrambledmegs Jun 13, 2023
988cc1d
marged
jayriverking Jun 13, 2023
1814863
fixed wave 06
jayriverking Jun 13, 2023
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
50 changes: 49 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,55 @@
<link rel="stylesheet" href="styles/index.css" />
</head>
<body>
<script src="./src/index.js"></script>
<header>
<h1>Weather Report for the city of <span id="city-display"></span>!</h1>
</header>
<div class="left-side-container">
<section class="temperature-section">
<h3>Temperature</h3>
<div class="temp-btn-sect">
<button type="button" id="up-button">
⬆️
</button>
<p id="temperature-now">50</p>
<button id="button-down">
⬇️
</button>
</div>
<button id="get-temp">
Get Realtime Temperature!
</button>
</section>
<section class="sky-menu">
<label for="change-sky" >Sky Menu:</label>
<select name="skies" id="change-sky">
<option value="">--Please choose a sky--</option>
<option value="sunny">☀️☀️ Sunny ☀️☀️</option>
<option value="cloudy">☁️☁️ Cloudy ☁️☁️</option>
<option value="rainy">☔️⛈️ Rainy ⛈️☔️</option>
<option value="snowy">☃️❄️ Snowy ❄️☃️</option>
</select>
</section>
<section class="city-choice">
<h3>City Name</h3>
<label for="cityname"></label>
<input type="text" id="city-input" name="cityname" oninput="display();" placeholder="Enter a city">
<button id="resetbtn">Reset</button>
</section>
</div>
<div class="right-side-container">
<section>
<h2>Weather Garden</h2>
<div id="weather-garden">
<p id="chosen-sky-emojis"></p>
<p id="weather-emojis">"🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷"</p>
</div>
</section>
</div>
<footer>
<p>&copy; 2023 Jay and Megan</p>
</footer>
<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="./src/index.js"></script>
</body>
</html>
183 changes: 183 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const state ={
temp: 0,
number: document.getElementById("temperature-now"),
}
Comment on lines +1 to +4

Choose a reason for hiding this comment

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

Love how you all chose to use this psuedostate! I think that it is great practice for what you will see in React though it will be utilized differently!


const upButton = document.getElementById("up-button");
const downButton = document.getElementById("button-down");
const tempButton = document.getElementById("get-temp")
// let number = document.getElementById("temperature-now");
// let temp = parseFloat(number.innerText);
state.temp = parseFloat(state.number.innerText);
const weatherGarden = document.getElementById('weather-garden');
const weatherEmojis = document.getElementById('weather-emojis');
const cityDisplay = document.getElementById("city-display")
const cityId = document.getElementById("city-input")
const skyOptions = document.getElementById('change-sky');
const skyEmojis = document.getElementById('chosen-sky-emojis');
const resetBtn = document.getElementById('resetbtn');
Comment on lines +6 to +18

Choose a reason for hiding this comment

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

Pieces of code like this are usually found in an event handler that runs on the event DOMContentLoaded, basically once the page is html is loaded on the webpage you will run a bunch of initial logic such as grabbing elements and adding event handlers to them. It will look something like this:

document.addEventListener("DOMContentLoaded", function () {
    const increaseTemp = document.querySelector("#increase-temp");
    const decreaseTemp = document.querySelector("#decrease-temp");
    const displayTemp = document.querySelector("#display-temp");
    const resetButton = document.querySelector("#reset-button"); 
    const searchButton = document.querySelector("#search-button");
    const cityName = document.getElementById("city-name");
    const cityInput = document.getElementById("city-input");
    const selectSky = document.querySelector("#sky-dropdown");
    const result = document.querySelector("#sky");
    const landscape = document.querySelector("#landscape");
    
    increaseTemp.addEventListener("click", increaseTemperature);
    decreaseTemp.addEventListener("click", decreaseTemperature);
    ...
}

This is also usually found at the bottom of the file too, that way you can put all your function definitions for event handlers above it!







function display() {
cityDisplay.innerText = cityId.value;
}

// console.log('curret temp', number.innerText);

const incrementNum = () => {
state.number.innerText = state.temp++;
}
// color changing function
const colorTemp = () => {

if (state.temp < 49){
state.number.style.color = "teal";
}
else if (state.temp < 59){
state.number.style.color = "green";
}
else if (state.temp < 69){
state.number.style.color = "yellow";
}
else if (state.temp < 79){
state.number.style.color = "orange";
}
else {

state.number.style.color = "red";
}

}

skyOptions.addEventListener('change', () => {
const skyValue = document.getElementById('change-sky').value;
if (skyValue == 'sunny') {
skyEmojis.innerText = '☀️☀️ ☁️ ☀️☁️ ☀️ ☁️☀️☀️';
} else if (skyValue =='cloudy') {
skyEmojis.innerText = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️';
} else if (skyValue == 'rainy') {
skyEmojis.innerText = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧';
} else if (skyValue == 'snowy') {
skyEmojis.innerText = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨';
} else {
skyEmojis.innerText = '';
}
})


const weatherGardenChanges = () => {

if (state.temp < 59){
weatherGarden.style.backgroundColor = "green";
weatherEmojis.innerHTML = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲"
}
else if (state.temp < 69){
weatherGarden.style.backgroundColor = "yellow";
weatherEmojis.innerHTML = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃"
}
else if (state.temp < 79){
weatherGarden.style.backgroundColor = "orange";
weatherEmojis.innerHTML = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷"
}
else {
weatherGarden.style.backgroundColor = "red";
weatherEmojis.innerHTML = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂"
}

}


upButton.addEventListener("click", () => {
console.log(state.temp);
incrementNum();
colorTemp(state.temp);
weatherGardenChanges(state.temp);
});


const decrementNum = () => {
state.number.innerText = state.temp--;
}

downButton.addEventListener("click", () => {
console.log(state.temp);
decrementNum()
colorTemp(state.temp)
weatherGardenChanges(state.temp);
});

const getLanLon = (city) => {
return axios.get(`http://localhost:5000/location?q=${city}`)
.then(response => {
let lat = response.data[0].lat
let lon = response.data[0].lon
console.log(response.data[0].display_name)
return [lat, lon]
})
.catch(error => {
console.log(error)
})
}
Comment on lines +113 to +124

Choose a reason for hiding this comment

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

Here's an alternative to promise chaining! You can use the async/await keywords to have your function wait until a promise is fulfilled and then you pass the results of that promise to other pieces of your function like assigning your return values as variables or other things like that. It looks something like this:

const findCityLocation = async () => {
    let lat;
    let lon;
    const resp = await axios.get('http://127.0.0.1:5000/location', {
        params: {
            q: document.getElementById("city").value
        }
    })
    
    try {
      [lat, lon] = resp.data[0]
      getWeather({ lat: lat, lon: lon});
    } catch (error) {
       console.log(error)
    }
};


const getWeather = (coords) => {
let lat = coords[0]
let lon = coords[1]
return axios.get(`http://localhost:5000/weather?lat=${lat}&lon=${lon}`)
.then(response => {
console.log(response.data.main.temp)
return response.data.main.temp
}).catch(error => {
console.log(error)
})
}

// should this be async-await so that I can change the innerTEXT? probably yes! (unless I can use .then to change the innerText (lol))

// tempButton.addEventListener("click", () => {
// const cityNow = cityDisplay.innerText;
// console.log(cityNow)
// getLanLon(cityNow).then(resp => getWeather(resp))

// })

const kelvinToFarenheit = (k) => {
return Math.floor((k - 273.15) * 9/5 + 32);
}

tempButton.addEventListener("click", () => {
const cityNow = cityDisplay.innerText;
console.log(cityNow)
getLanLon(cityNow)
.then(resp => getWeather(resp))
.then(weather => {
state.temp = kelvinToFarenheit(weather);
state.number.innerText = state.temp;
colorTemp(state.temp);
weatherGardenChanges();
})


});


document.addEventListener("load", colorTemp(state.temp))
document.addEventListener("load", weatherGardenChanges())

// resetBtn.addEventListener('click', () => {
// const cityInput = document.getElementById('city-input');
// console.log('click')
// cityInput.reset()
// })


// document.getElementById("myForm").reset()


resetBtn.addEventListener("click",() =>{
cityDisplay.innerText = "";
cityId.value = ""
} )

Choose a reason for hiding this comment

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

Awesome job everyone! You really ate this one up! Please feel free to reach out to me if you have any questions about the comments I left or if you want to discuss anything in greater detail! ⭐️

146 changes: 146 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
body {
background-color: #1b69f9;
font-family: Rubik, sans-serif;
display: flex;
flex-direction:row;
flex-wrap: wrap;
}

header {
width: 100vw;
height: 100px;
text-align: center;
color: #ffffff;
}

.left-side-container {
width: 35vw;
}

.right-side-container {
width: 61vw;
/* border: solid red; */
display: flex;
justify-content: center;
text-align: center;
align-items: center;
}

.right-side-container h2 {
color:#ffffff;
}

.temperature-section {
height: 200px;
width: 100%;
background-color: #ffffff;
border-radius: 10px;
display: flex;
flex-wrap: wrap;
}

.temperature-section h3{
text-align: center;
width: 100%;
height: 1px;
}

.temp-btn-sect {
margin: 0px 30px;
/* padding: 0px 0px 0px 10px; */
font-size: 25px;
}

#get-temp {
margin: 40px 0px;
padding: 10px 5px;
background-color: #1b69f9;
color:#ffffff;
border-radius: 10px;
border: none;
font-size: 16px;
}

.sky-menu {
background-color: #ffffff;
border-radius: 10px;
height: 80px;
width: auto;
margin: 20px 0px;
padding: 30px;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}


#change-sky {
width: 20vw;
height: auto;
margin: 50px;
text-align: center;
}

.city-choice {
background-color: #ffffff;
border-radius: 10px;
text-align: center;
height: 140px;
width: auto;
}

.city-choice h3 {
padding: 20px 0px 0px 0px;
font-size: 20px;
}

#city-input {
border-radius: 5px;
}

#resetbtn {
background-color: #1b69f9;
border-radius: 10px;
border: none;
padding: 10px 20px 10px 20px;
margin: 0px 0px 0px 10px;
color: #ffffff;

}

#weather-garden {
/* border: solid black; */
border-radius: 10px;
height: 200px;
width: 40vw;;
background-color: #ddffff;
}

#weather-garden p {
font-size: 25px;;
}

#chosen-sky-emojis {
justify-content: center;
height: 40px;
width: auto;
/* border: solid green; */
padding-top: 30px;
}

#weather-emojis {
width: auto;
height: 40px;
margin: 70px 0px 0px 0px;
}



footer {
border-top: solid #ffffff;
width: 100vw;
height: 10vh;
margin: 50px 50px;
text-align: center;
}