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
Copy Markdown

No description provided.

Comment thread style.css
Comment on lines +29 to +32
.container {
width: 100%;
margin: 0 auto;
}
Copy link
Copy Markdown

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.

Comment thread main.js
@@ -0,0 +1,220 @@
// Set current date
const date = new Date();
const options = { weekday: 'long'};
Copy link
Copy Markdown

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

Comment thread main.js

const formattedDates = [];

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

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 thread main.js
Comment on lines +18 to +20
var currentWeather = [];

var weatherForecast = [];
Copy link
Copy Markdown

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 thread main.js
Comment on lines +23 to +25
var searchLocation = document.querySelector('#search-query').value;
var words = searchLocation.split(' ');
var city = words.join('/');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

var is not es6

Comment thread main.js
};

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

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

Comment thread main.js
renderWeather();
};

var renderWeather = function() {
Copy link
Copy Markdown

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 thread main.js
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));
};
Copy link
Copy Markdown

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));
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Way more readable!!!

Comment thread main.js
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]
})
Copy link
Copy Markdown

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

Comment thread main.js
renderForecast();
};

var renderForecast = function() {
Copy link
Copy Markdown

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