-
Notifications
You must be signed in to change notification settings - Fork 88
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
Sea Turtles-Jenny C #79
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -4,9 +4,56 @@ | |
<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 href="/styles/index.css" rel="stylesheet" /> | ||
|
||
<title>Weather Report</title> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Weather Report</h1> | ||
</header> | ||
<main> | ||
<div class="grid-display"> | ||
<img id="sunnyday" src="/ada-project-docs/images/sunnyday.jpg" alt="a sunnyday" /> | ||
<div id="cityTempcontainer"> | ||
<h1 id="cityLabel">Honolulu</h1> | ||
<h1 id="tempLabel">70°F</h1> | ||
|
||
</div> | ||
</div> | ||
|
||
<div class="grid-display"> | ||
|
||
<section> | ||
<h1>Change the Sky</h1> | ||
<select id="sky-types"> | ||
<option value="sunny">Sunny</option> | ||
<option value="cloudy">Cloudy</option> | ||
<option value="rainy">Rainy</option> | ||
<option value="snowy">Snowy</option> | ||
</select> | ||
<div id="sky-horizon">☁️ ☁️ ☁️🌞☁️ ☁️ ☁️</div> | ||
</section> | ||
<h1 id="tempLabel" class="green">Temperature</h1> | ||
<span id="tempUp">⬆️</span> | ||
<span id="tempDown">⬇️</span> | ||
<section> | ||
<div id="landscape">🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷</div> | ||
<div id="searchContainer"> | ||
<label for="citySearch">Search City</label> | ||
<input type="search" id="citySearch" name="citySearch"> | ||
<button id="submitCity">Submit</button> | ||
<button id="reset">Reset</button> | ||
</div> | ||
</section> | ||
|
||
</div> | ||
</main> | ||
<footer> | ||
</footer> | ||
Comment on lines
+52
to
+53
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 don't need the footer tag if you do not have a footer
Comment on lines
+52
to
+53
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 don't need the footer tag if you do not have a footer |
||
|
||
|
||
<script src="src/index.js" type="text/javascript"></script> | ||
<script src="./node_modules/axios/dist/axios.min.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "^0.27.2" | ||
"axios": "^0.27.2", | ||
"prettier": "^2.6.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
'use strict'; | ||
|
||
const state = { | ||
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. 👍🏽 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. 👍🏽 |
||
city: 'Honolulu', | ||
temperature: 70, | ||
lat: 21.315603, | ||
lon: -157.858, | ||
}; | ||
|
||
const updateTempLabel = () => { | ||
const tempLabel = document.getElementById('tempLabel'); | ||
tempLabel.textContent = `${state.temperature}°F`; | ||
const changeLandscape = document.getElementById('landscape'); | ||
|
||
let landscape = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷'; | ||
if (state.temperature >= 80) { | ||
tempLabel.className = 'red'; | ||
landscape = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂'; | ||
} else if (state.temperature >= 70) { | ||
tempLabel.className = 'orange'; | ||
landscape = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷'; | ||
} else if (state.temperature >= 60) { | ||
tempLabel.className = 'yellow'; | ||
landscape = '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃'; | ||
} else if (state.temperature >= 50) { | ||
tempLabel.className = 'green'; | ||
landscape = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
} else if (state.temperature <= 49) { | ||
tempLabel.className = 'teal'; | ||
landscape = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
} | ||
console.log(tempLabel.className); | ||
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 this console log after debugging 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 this console log after debugging |
||
changeLandscape.textContent = `${landscape}`; | ||
}; | ||
|
||
const increaseTemp = () => { | ||
state.temperature += 1; | ||
updateTempLabel(); | ||
console.log('increase temp'); | ||
}; | ||
|
||
const decreaseTemp = () => { | ||
state.temperature -= 1; | ||
updateTempLabel(); | ||
console.log('decrease temp'); | ||
}; | ||
Comment on lines
+36
to
+46
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. functions look good but remove your console logs
Comment on lines
+36
to
+46
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. functions look good but remove your console logs |
||
|
||
const updateCityLabel = () => { | ||
const citySearch = document.getElementById('cityLabel'); | ||
citySearch.textContent = `${state.city}`; | ||
}; | ||
|
||
const updateCityWithTemp = () => { | ||
updateCity(); | ||
getLatAndLong(); | ||
}; | ||
|
||
const updateCity = () => { | ||
const searchFieldInput = document.getElementById('citySearch'); | ||
state.city = searchFieldInput.value; | ||
updateCityLabel(); | ||
}; | ||
|
||
const updateTheSky = () => { | ||
const skyLabel = document.querySelector('#sky-types').value; | ||
const changeSky = document.getElementById('sky-horizon'); | ||
|
||
const imageElement = document.querySelector('#sunnyday'); | ||
|
||
let sky = '☁️ ☁️ ☁️🌞☁️ ☁️ ☁️'; | ||
if (skyLabel === 'sunny') { | ||
sky = '☁️ ☁️ ☁️🌞☁️ ☁️ ☁️'; | ||
imageElement.src = '../ada-project-docs/images/sunnyday.jpg'; | ||
} else if (skyLabel === 'cloudy') { | ||
sky = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️'; | ||
imageElement.src = '../ada-project-docs/images/cloudyday.jpg'; | ||
} else if (skyLabel === 'rainy') { | ||
sky = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧'; | ||
imageElement.src = '../ada-project-docs/images/rainyday.jpg'; | ||
} else if (skyLabel === 'snowy') { | ||
sky = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨'; | ||
imageElement.src = '../ada-project-docs/images/winterday.jpg'; | ||
} | ||
changeSky.textContent = `${sky}`; | ||
}; | ||
|
||
const resetCity = () => { | ||
const cityName = document.getElementById('citySearch'); | ||
cityName.value = ''; | ||
state.city = 'Honolulu'; | ||
updateCityLabel(); | ||
|
||
const skyHorizon = document.getElementById('sky-horizon'); | ||
skyHorizon.textContent = '☁️ ☁️ ☁️🌞☁️ ☁️ ☁️'; | ||
}; | ||
|
||
const registerEventHandlers = () => { | ||
const tempUpButton = document.getElementById('tempUp'); | ||
tempUpButton.addEventListener('click', increaseTemp); | ||
const tempDownButton = document.getElementById('tempDown'); | ||
tempDownButton.addEventListener('click', decreaseTemp); | ||
const submitCityButton = document.getElementById('submitCity'); | ||
submitCityButton.addEventListener('click', updateCityWithTemp); | ||
const selectItem = document.getElementById('sky-types'); | ||
selectItem.addEventListener('change', updateTheSky); | ||
const resetButton = document.getElementById('reset'); | ||
resetButton.addEventListener('click', resetCity); | ||
const citySearchEl = document.getElementById('citySearch'); | ||
citySearchEl.addEventListener('input', updateCity); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); | ||
|
||
const getLatAndLong = () => { | ||
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. small note. I would move this function and the function below this before you register the event handlers. Just to make the code more readable. 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. ok, got it. I thought line 103 was only for all the events so I put it before the API calls. I see now that I put it at the end of index. Thank you 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. small note. I would move this function and the function below this before you register the event handlers. Just to make the code more readable. |
||
axios | ||
.get('http://localhost:5000/location', { | ||
params: { | ||
q: state.city, | ||
}, | ||
}) | ||
.then((response) => { | ||
state.lat = response.data[0]['lat']; | ||
state.lon = response.data[0]['lon']; | ||
getRealTimeWeather(); | ||
}) | ||
.catch((error) => { | ||
console.log('Error finding latitude and longitude,', error); | ||
}); | ||
}; | ||
|
||
const getRealTimeWeather = () => { | ||
axios | ||
.get('http://localhost:5000/weather', { | ||
params: { | ||
lat: state.lat, | ||
lon: state.lon, | ||
}, | ||
}) | ||
.then((response) => { | ||
let tempInKelvin = response.data.current.temp; | ||
let realTimeWeather = Math.floor((tempInKelvin - 273.15) * (9 / 5) + 32); | ||
state.temperature = realTimeWeather; | ||
updateTempLabel(); | ||
}) | ||
.catch((error) => { | ||
console.log(`Error in real time weather: ${error}`); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
header h1 { | ||
margin-left: 500px; | ||
margin-top: 20px; | ||
} | ||
main { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
height: 580px; | ||
width: 900px; | ||
margin: 0 auto; | ||
margin-top: 100px; | ||
} | ||
|
||
#sunnyday { | ||
width: 100%; | ||
} | ||
|
||
.grid-display { | ||
height: 100%; | ||
} | ||
|
||
.grid-display:nth-child(1){ | ||
background-color: gray; | ||
} | ||
|
||
.grid-display:nth-child(2){ | ||
background-color: lightgray; | ||
} | ||
|
||
.red{ | ||
color: red; | ||
} | ||
|
||
.orange{ | ||
color: orange; | ||
} | ||
|
||
.yellow{ | ||
color: yellow; | ||
} | ||
|
||
.green{ | ||
color: green; | ||
} | ||
|
||
.teal{ | ||
color: teal; | ||
} |
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.
Most of your code in HTML is semantic. I think in this particular place you could've used something else besides a div. Here is a document you can use to walk through when to use particular tags:
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.
Thank you so much Trenisha.