Skip to content

Jacob's Weather Project#211

Open
jacobecox wants to merge 1 commit intoprojectshft:masterfrom
jacobecox:master
Open

Jacob's Weather Project#211
jacobecox wants to merge 1 commit intoprojectshft:masterfrom
jacobecox:master

Conversation

@jacobecox
Copy link

No description provided.

Comment on lines +29 to +32
.container {
width: 100%;
margin: 0 auto;
}

Choose a reason for hiding this comment

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

the whole point of using bootstrap is to use to avoid creating the classes yourself.

@@ -0,0 +1,220 @@
// Set current date
const date = new Date();
const options = { weekday: 'long'};

Choose a reason for hiding this comment

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

options is too generic, dateOptions is a more specific name


const formattedDates = [];

for (let i = 0; i < 5; i++) {

Choose a reason for hiding this comment

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

next time wrap this in a function to give context of the purpose of this code

Comment on lines +18 to +20
var currentWeather = [];

var weatherForecast = [];

Choose a reason for hiding this comment

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

started using const, why not let?

Comment on lines +23 to +25
var searchLocation = document.querySelector('#search-query').value;
var words = searchLocation.split(' ');
var city = words.join('/');

Choose a reason for hiding this comment

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

var is not es6

};

var fetchWeather = function(data) {
const apiKey = '0e79198cac257d0139d13e84e8617759'

Choose a reason for hiding this comment

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

api key is the same, can be defined once at the top of the file or passed a param

renderWeather();
};

var renderWeather = function() {

Choose a reason for hiding this comment

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

not es6 Function declarations

Comment on lines +94 to +104
var fetchPlace = function(city) {
const url = 'http://api.openweathermap.org/geo/1.0/direct?q=';
const apiKey = '&appid=0e79198cac257d0139d13e84e8617759'
const fullUrl = url + city + apiKey;
fetch(fullUrl, {
method: 'GET',
dataType: 'json'
})
.then(data => data.json())
.then(data => fetchForecast(data));
};

Choose a reason for hiding this comment

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

You are doing the same 3 times, you could have a generic function that takes api, url and callback for the data and reuse it.
Important DRY principle.

Suggested change
var fetchPlace = function(city) {
const url = 'http://api.openweathermap.org/geo/1.0/direct?q=';
const apiKey = '&appid=0e79198cac257d0139d13e84e8617759'
const fullUrl = url + city + apiKey;
fetch(fullUrl, {
method: 'GET',
dataType: 'json'
})
.then(data => data.json())
.then(data => fetchForecast(data));
};
const fetchPlace = (fullUrl, callback) => {
fetch(fullUrl, {
method: 'GET',
dataType: 'json'
})
.then(data => data.json())
.then(data => callBack(data));
};

Choose a reason for hiding this comment

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

Way more readable!!!

Comment on lines +125 to +158
dayOne.push({
conditions: data.list[0].weather[0].main,
temp: Math.round(data.list[0].main.temp),
icon: `https://openweathermap.org/img/wn/${data.list[0].weather[0].icon}@2x.png`,
day: formattedDates[0]
})

dayTwo.push({
conditions: data.list[7].weather[0].main,
temp: Math.round(data.list[7].main.temp),
icon: `https://openweathermap.org/img/wn/${data.list[7].weather[0].icon}@2x.png`,
day: formattedDates[1]
})

dayThree.push({
conditions: data.list[15].weather[0].main,
temp: Math.round(data.list[15].main.temp),
icon: `https://openweathermap.org/img/wn/${data.list[15].weather[0].icon}@2x.png`,
day: formattedDates[2]
})

dayFour.push({
conditions: data.list[23].weather[0].main,
temp: Math.round(data.list[23].main.temp),
icon: `https://openweathermap.org/img/wn/${data.list[23].weather[0].icon}@2x.png`,
day: formattedDates[3]
})

dayFive.push({
conditions: data.list[31].weather[0].main,
temp: Math.round(data.list[31].main.temp),
icon: `https://openweathermap.org/img/wn/${data.list[31].weather[0].icon}@2x.png`,
day: formattedDates[4]
})

Choose a reason for hiding this comment

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

DRY, could have used forEach day of the week.
Helper methods are your friends.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

renderForecast();
};

var renderForecast = function() {

Choose a reason for hiding this comment

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

also this type of function could have been reused. You can create a more 'dumb' implementation that takes querySelector, template as params and makes the action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants