-
Notifications
You must be signed in to change notification settings - Fork 6
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
Emily - HW 04 #3
base: master
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
|
||
# Build a Weather App | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
* { | ||
font-family: Helvetica, Arial, sans-serif; | ||
} | ||
|
||
body { | ||
background-color: white | ||
} | ||
|
||
current-temp { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,89 @@ | ||
$(function () { | ||
$(document).ready(function () { | ||
$('#submit-btn').click(() => { | ||
|
||
refreshSearch() | ||
|
||
const city = $('#city-type').val() | ||
|
||
getWeatherByCity(city) | ||
|
||
}) | ||
|
||
|
||
function getWeatherByCity (city) { | ||
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. @kcycle nice work using the standard promise syntax here. |
||
axios.get(`http://api.openweathermap.org/data/2.5/weather?q=${city}&APPID=1c739a9713a0919a3024a089c3b027df`) | ||
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. @kcycle it's recommended that you use |
||
.then((response) => { | ||
console.log(response.data) | ||
displayCityName(response.data.name) | ||
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. @kcycle nice! I like the use of separate functions to display each element. Putting all the display logic into one function would have also adhered to the SRP rule as well. |
||
displayCurrentTemperature(convertToFahrenheit(response.data.main.temp)) | ||
displayWeatherDescription(response.data.weather[0].description) | ||
displayMinTemp(convertToFahrenheit(response.data.main.temp_min)) | ||
displayMaxTemp(convertToFahrenheit(response.data.main.temp_max)) | ||
|
||
}).catch((error) => { | ||
console.log(error) | ||
}) | ||
|
||
} | ||
|
||
|
||
|
||
|
||
function displayCityName (cityName) { | ||
$('#current-city').append( | ||
`<h4>Current City:</h4> <p>${cityName}</p>`) | ||
} | ||
|
||
function displayCurrentTemperature (temperature) { | ||
$('#current-temp').append( | ||
`<h4>Current Temperature:</h4> <p>${temperature} F°</p>`) | ||
setTempFontColor(temperature) | ||
} | ||
|
||
function displayWeatherDescription (description) { | ||
$('#description').append( | ||
`<h4>Description:</h4> <p>${description}</p>`) | ||
} | ||
|
||
function displayMinTemp (temperature) { | ||
$('#min-temp').append( | ||
`<h4>Today's Low:</h4> <p>${temperature} F°</p>`) | ||
} | ||
|
||
function displayMaxTemp (temperature) { | ||
$('#max-temp').append( | ||
`<h4>Today's High:</h4> <p>${temperature} F°</p>`) | ||
} | ||
|
||
function convertToFahrenheit (kelvinUnits) { | ||
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. @kcycle nice job creating a separate function to convert from Celcius to Fahrenheit. However, OpenWeatherMap's API does this work for you by passing an additional request parameter with the API call: See the docs here: https://openweathermap.org/current#data And here's how I use it in the solution: https://github.com/jsd20191008/weather-api-app-solution/blob/master/js/main-promises.js#L56 |
||
return parseInt((kelvinUnits-273.15)*(9/5)+32) | ||
} | ||
|
||
function setTempFontColor (temperature) { | ||
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. @kcycle great job breaking out this logic into a separate function. the only suggestion here would be to use |
||
if (temperature > 85) { | ||
$('#current-temp').css({ | ||
color: "red" | ||
}) | ||
} | ||
if (temperature < 40) { | ||
$('#current-temp').css({ | ||
color: "blue" | ||
}) | ||
} | ||
} | ||
|
||
function refreshSearch () { | ||
$('#current-city').html('') | ||
$('#current-temp').html('') | ||
$('#description').html('') | ||
$('#min-temp').html('') | ||
$('#max-temp').html('') | ||
} | ||
|
||
|
||
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. @kcycle be careful regarding unnecessary blank lines...will not result in an error, but it makes the code harder to scan. |
||
|
||
|
||
|
||
|
||
|
||
}) |
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.
@kcycle nice updates to the UI