Skip to content

Week one homework#1

Merged
Catsudemo merged 1 commit into
masterfrom
week1
Aug 4, 2019
Merged

Week one homework#1
Catsudemo merged 1 commit into
masterfrom
week1

Conversation

@Catsudemo

Copy link
Copy Markdown
Owner

No description provided.

@Catsudemo Catsudemo merged commit 6793b69 into master Aug 4, 2019

@mattiaslundberg mattiaslundberg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Almost there

I know that it's a lot of comments. Most are for general improvement of the code and so that you can learn. The only one I want to see fixed before approving is that you should use the main function. (Please read the rest of the comments and have them in mind for your future homeworks)

Comment thread homework/index.js
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';

function displayContrib(contributor, contributions, avatar) {
const eachPersonUl = document.createElement('ul');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I find this function and the displayRepo function hard to read, try to add some blank lines where it's possible to logically separate different things. For example:

          const eachPersonUl = document.createElement('ul');

          const contributorName = document.createElement('li');
	  contributorName.innerText = `Username: ${contributor}`;
	  eachPersonUl.appendChild(contributorName);

	  const eachContributions = document.createElement('li');
	  eachContributions.innerText = `Contributions: ${contributions}`;

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, as the code provides the createAndAppend function, it's a good idea to actually use it. That would help with readability.

Comment thread homework/index.js
eachPersonUl.appendChild(eachContributions);
contribDiv.appendChild(eachPersonUl);
const eachAvatar = document.createElement('IMG');
eachAvatar.innerhtml = `<img src=${avatar}'>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I find this row a bit strange (and it looks like it isn't working as expected). You can actually set the attribute like this (and I think it would work):

eachAvatar.setAttribute('src', avatar);

Comment thread homework/index.js

const selectElement = document.querySelector('.selector');

selectElement.addEventListener('change', event => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks like you're doing this outside of the main function. This can cause problems down the line (but looks like it's working during my tests), as some things might not be ready before window.onload is called. Please give moving the code inside the main function a try!

Comment thread homework/index.js
} else {
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
}
const repoSelector = document.querySelector('#repoSelect');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From what I can see these variables aren't used, it's always a good idea to remove stuff that you don't need. Keeping them around will likely confuse you the next time you look at the code.

Neat freak

Comment thread homework/index.js
let repoURL = `https://api.github.com/repos/HackYourFuture/${repo}`;
let contribURL = `https://api.github.com/repos/HackYourFuture/${repo}/contributors`;

main(HYF_REPOS_URL);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure why you're calling main here, you should probably remove it.

Comment thread homework/index.js
.map(repo => repo.name)
.sort()
.forEach(name => {
createAndAppend('OPTION', repoSelector, { text: name, value: name });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems like you add options to the select box multiple times, see if you can figure out what's causing that!

Comment thread homework/newStyle.css
padding: 10px;
}

#footer {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is never used, so it's best to remove it.

Comment thread homework/newStyle.css
color: #444;
}

#repo {

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 contents of #repo and #contribDiv looks the same, is there some way to avoid repeating all the code?

Comment thread homework/newStyle.css
padding: 5px;
}

#main-content {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This isn't used, so it's best to remove it.

Comment thread homework/newStyle.css
margin: 20px;
}

@media screen and (max-width: 600px) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, looks good on mobile!

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