-
Notifications
You must be signed in to change notification settings - Fork 527
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
Heather M - Sea Turtles C17 #16
base: main
Are you sure you want to change the base?
Changes from 5 commits
e1dd871
e1272ba
44e537e
c9e0ea8
1d0ebb1
88ec6ed
bd5204c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode | ||
.DS_Store | ||
node_modules | ||
.cache | ||
.cache | ||
jsExample.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,64 @@ | |
<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"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.75"> | ||
<title>Weather Report</title> | ||
<!-- Link to Style Sheet --> | ||
<link href="styles/style.css" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
|
||
<div id="weather_body"> | ||
<header> | ||
<a id="site_title" href="index.html"> | ||
<p>~ current temperature in ~</p> | ||
</a> | ||
<nav> | ||
<div><button id="search_location" alt="Search or Enter Location">⌖</button></div> | ||
<input type="search" id="location_text" value="Denver" placeholder="location"></input> | ||
<div><button id="refresh_weather" alt="Refresh">⇢</button></div> | ||
</nav> | ||
</header> | ||
<figure id="weather_display"> | ||
<text id="numeric_temperature">25</text> | ||
<div id="units_div"><button id="temperature_units">°C</button></div> | ||
</figure> | ||
<figure id="change_temperature"> | ||
<button id="decrease"alt="Decrease Temperature"> - </button> | ||
<button id="reset"alt="Reset Temperature">⃔ </button> | ||
<button id="increase"alt="Increase Temperature"> + </button> | ||
</figure> | ||
Comment on lines
+23
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was curious why you decided on the figure tag. Normally you would see it with an img tag so you could embed an image with a caption. You could also use it for diagrams or listing code. An example here: https://www.geeksforgeeks.org/html5-figure-tag/ Here is an example of a flowchart you could look at for guidance on what tags to use for that focus on semantic html: |
||
<div id="sky"> | ||
<select name="sky_selector" id="sky_selector"> | ||
<option value=""> --- sky --- </option> | ||
<option value="sunny">sunny</option> | ||
<option value="cloudy">cloudy</option> | ||
<option value="rainy">rainy</option> | ||
<option value="snowy">snowy</option> | ||
</select> | ||
</div> | ||
<div id="sky_display" class="ascii_art"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this different approach to the sky display and landscape display |
||
<pre> | ||
| : : : : : │ | ||
| : : : : : │ | ||
| : : : : : │ | ||
</pre> | ||
</div> | ||
<div id="landscape" class="ascii_art"> | ||
<pre> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good use of pre tag to keep your sky/landscape formatted |
||
┼┼┼│ │ ┼┼│ | ||
┼┼┼┼┐ ┼┼┼│ | ||
┼┼┼┼│ * │┼┼┼┼│ | ||
┼┼┼┼┘ * │ ┼┼┼│ | ||
┼ ├────┼ ───────│ ┼┼┼│ | ||
┼┼┼┼│┐┐┐┐┐┐┐┐ ├├├├├├├├├──│┼ ┼┼┼│ | ||
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼ | ||
******************************** | ||
******************************** | ||
******************************** | ||
</pre> | ||
</div> | ||
</div> | ||
<script src="src/index.js"></script> | ||
<script src="./node_modules/axios/dist/axios.min.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
// import axios from 'axios'; | ||
// const axios = require('axios'); | ||
|
||
const state = { | ||
temp: 25, | ||
tempUnits: '°C', | ||
city: 'Denver', | ||
lat: 39.7392, | ||
lon: -104.985, | ||
sky: 'sunny', | ||
}; | ||
|
||
const landscapes = { | ||
cold: '-----cold-----\ | ||
I X I I I I I I I I I I\ | ||
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\ | ||
********************************', | ||
cool: '***cool***', | ||
neutral: | ||
'\ | ||
----neutral-----\ | ||
┼┼┼│ │ ┼┼│\ | ||
┼┼┼┼┐ ┼┼┼│\ | ||
┼┼┼┼│ * │┼┼┼┼│\ | ||
┼┼┼┼┘ * │ ┼┼┼│\ | ||
┼ ├────┼ ───────│ ┼┼┼│\ | ||
┼┼┼┼│┐┐┐┐┐┐┐┐ ├├├├├├├├├──│┼ ┼┼┼│\ | ||
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\ | ||
********************************\ | ||
********************************\ | ||
********************************', | ||
warm: '^^^^^^warm^^^^^^', | ||
hot: '<<<<<hot>>>>>', | ||
}; | ||
|
||
const skies = { | ||
sunny: | ||
'\ | ||
| : : : : : │\ | ||
| : : : : : │\ | ||
| : : : : : │', | ||
cloudy: | ||
'\ | ||
| : = : = : = : = : │\ | ||
| : = : = : = : = : = │\ | ||
| = : = : = : = : = : │', | ||
rainy: | ||
'\ | ||
| : :: : : : : : : : : │\ | ||
| : : : : : : : : : : │\ | ||
| : : : :: : :: : :: : │', | ||
snowy: | ||
'\ | ||
| * * * * * * * │\ | ||
| * * * * * * * * * *│\ | ||
| * * * * * * ** * │', | ||
}; | ||
|
||
const convertFtoC = (temp) => { | ||
return Math.round(((temp - 32) * 5) / 9); | ||
}; | ||
|
||
const convertKtoC = (temp) => { | ||
return Math.round(temp - 273.15); | ||
}; | ||
|
||
const convertCtoF = (temp) => { | ||
return Math.round(temp * (9 / 5) + 32); | ||
}; | ||
|
||
const changeLandscapeTemp = () => { | ||
let color = 'rgba(150, 50, 110, 0.5)'; | ||
let degC = 0.0; | ||
let landscape = landscapes.neutral; | ||
|
||
if (state.tempUnits === '°F') { | ||
degC = convertFtoC(state.temp); | ||
} else { | ||
degC = state.temp; | ||
} | ||
if (degC > 30) { | ||
landscape = landscapes.hot; | ||
color = 'rgba(150, 90, 30, 0.5)'; | ||
} else if (degC > 25) { | ||
landscape = landscapes.warm; | ||
color = 'rgba(120, 60, 40, 0.5)'; | ||
} else if (degC > 15) { | ||
landscape = landscapes.neutral; | ||
color = 'rgba(100, 110, 10, 0.5)'; | ||
} else if (degC > 0) { | ||
landscape = landscapes.cool; | ||
color = 'rgba(80, 10, 110, 0.5)'; | ||
} else if (degC <= 0) { | ||
landscape = landscapes.cold; | ||
color = 'rgba(5, 5, 110, 0.5)'; | ||
} | ||
|
||
let backgroundColors = `radial-gradient(${color}, rgba(0, 0, 0, 0))`; | ||
|
||
const backgroundColor = document.getElementById('weather_body'); | ||
backgroundColor.style.backgroundImage = backgroundColors; | ||
|
||
const landscapeReturn = document.getElementById('landscape'); | ||
landscapeReturn.textContent = landscape; | ||
|
||
const tempContainer = document.querySelector('#numeric_temperature'); | ||
tempContainer.textContent = `${state.temp}`; | ||
|
||
const unitsContainer = document.querySelector('#temperature_units'); | ||
unitsContainer.textContent = `${state.tempUnits}`; | ||
}; | ||
|
||
const changeUnits = () => { | ||
const currentUnits = state.tempUnits; | ||
// document.getElementById('#temperature_units').textContent; | ||
// state.tempUnits = currentUnits; | ||
console.log('current units: ' + currentUnits); | ||
Comment on lines
+115
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove your console log and commented code |
||
if (currentUnits === '°C') { | ||
state.temp = convertCtoF(state.temp); | ||
state.tempUnits = '°F'; | ||
} else if (currentUnits === '°F') { | ||
state.temp = convertFtoC(state.temp); | ||
state.tempUnits = '°C'; | ||
} | ||
changeLandscapeTemp(); | ||
}; | ||
|
||
const increaseTemp = () => { | ||
state.temp += 1; | ||
changeLandscapeTemp(); | ||
}; | ||
|
||
const reset = () => { | ||
state.temp = 25; | ||
state.tempUnits = '°C'; | ||
changeLandscapeTemp(); | ||
resetLocation(); | ||
}; | ||
|
||
const decreaseTemp = () => { | ||
state.temp -= 1; | ||
changeLandscapeTemp(); | ||
}; | ||
|
||
const searchLocation = () => { | ||
axios | ||
.get('http://localhost:5000/location', { | ||
params: { | ||
q: state.city, | ||
}, | ||
}) | ||
.then((response) => { | ||
console.log('success!' + JSON.stringify(response.data[0])); | ||
state.lat = response.data[0].lat; | ||
state.lon = response.data[0].lon; | ||
searchTemperature(); | ||
}) | ||
.catch((error) => { | ||
console.log('searchLocation error: ' + error.response); | ||
}); | ||
}; | ||
|
||
const searchTemperature = () => { | ||
axios | ||
.get('http://localhost:5000/weather', { | ||
params: { | ||
lat: state.lat, | ||
lon: state.lon, | ||
}, | ||
}) | ||
.then((response) => { | ||
console.log('success!' + JSON.stringify(response.data.current.temp)); | ||
state.temp = convertKtoC(response.data.current.temp); | ||
changeLandscapeTemp(); | ||
}) | ||
.catch((error) => { | ||
console.log('searchTemperature error: ' + error.response); | ||
}); | ||
}; | ||
|
||
const changeCity = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I am typing in the input it should change the city name. From wave 3:
const cityNameInput = document.getElementById('cityNameInput');
cityNameInput.addEventListener('input', updateCityName); |
||
const newCity = document.getElementById('location_text').value; | ||
const cityDisplay = document.getElementById('location_text'); | ||
state.city = newCity; | ||
cityDisplay.textContent = state.city; | ||
}; | ||
|
||
const resetLocation = () => { | ||
const locationInput = document.getElementById('location_text'); | ||
locationInput.value = 'Denver'; | ||
changeCity(); | ||
}; | ||
|
||
const changeSky = () => { | ||
// const currentSky = state.sky; | ||
const skyInput = document.getElementById('sky_selector'); | ||
const skyValue = skyInput.options[skyInput.selectedIndex].value; | ||
console.log('sky_selector' + skyValue); | ||
state.sky = skyValue; | ||
const skyReturn = document.getElementById('sky_display'); | ||
skyReturn.textContent = skies[state.sky]; | ||
}; | ||
|
||
const registerEventHandlers = () => { | ||
changeCity(); | ||
const changeLocationOnInput = document.querySelector('#location_text'); | ||
changeLocationOnInput.addEventListener('change', searchLocation); | ||
|
||
changeCity(); | ||
const changeLocation = document.querySelector('#refresh_weather'); | ||
changeLocation.addEventListener('click', searchLocation); | ||
|
||
const changeUnitsButton = document.querySelector('#temperature_units'); | ||
changeUnitsButton.addEventListener('click', changeUnits); | ||
|
||
const increaseTempButton = document.querySelector('#increase'); | ||
increaseTempButton.addEventListener('click', increaseTemp); | ||
|
||
const resetButton = document.querySelector('#reset'); | ||
resetButton.addEventListener('click', reset); | ||
|
||
const decreaseTempButton = document.querySelector('#decrease'); | ||
decreaseTempButton.addEventListener('click', decreaseTemp); | ||
|
||
const skySelector = document.querySelector('#sky_selector'); | ||
skySelector.addEventListener('change', changeSky); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
html { | ||
font-size: min(max(2rem, 4vw), 30px); | ||
padding: calc(8px + 1.5625vw); | ||
text-align: center; | ||
} | ||
|
||
header { | ||
padding: calc(8px + 1.5625vw); | ||
} | ||
|
||
nav { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row; | ||
column-gap: 1rem; | ||
row-gap: 0rem; | ||
justify-content: center; | ||
} | ||
|
||
figure { | ||
flex-wrap: nowrap; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row; | ||
row-gap: 0rem; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
justify-content: center; | ||
flex: 25%; | ||
} | ||
|
||
#weather_body { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
background-image: | ||
radial-gradient(rgba(100, 110, 10, 0.5), rgba(0, 0, 0, 0)); | ||
} | ||
|
||
.ascii_art { | ||
font-family: monospace; | ||
font-size: 0.5rem; | ||
line-height: 0.5rem; | ||
text-align: center; | ||
max-width: 32ch; | ||
text-overflow: clip; | ||
} | ||
|
||
#location_text { | ||
font-weight: bold; | ||
font-size: large; | ||
text-align: center; | ||
} | ||
|
||
|
||
#weather_display { | ||
display: flex; | ||
} | ||
|
||
#numeric_temperature { | ||
font-size: 8rem; | ||
line-height: 90%; | ||
} | ||
|
||
#units_div { | ||
align-self: flex-start; | ||
flex-shrink: 2; | ||
} | ||
|
||
#change_temperature { | ||
gap: 1rem; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good