Skip to content

SOLUTION: JESÚS HERRERA & SOFÍA ROMERA#54

Open
Sofianct wants to merge 21 commits into
assembler-institute:mainfrom
Sofianct:main
Open

SOLUTION: JESÚS HERRERA & SOFÍA ROMERA#54
Sofianct wants to merge 21 commits into
assembler-institute:mainfrom
Sofianct:main

Conversation

@Sofianct

Copy link
Copy Markdown

No description provided.

Comment thread src/js/main.js
@@ -0,0 +1,109 @@

const postsURL = fetch("https://jsonplaceholder.typicode.com/posts/");
const contentBody = document.getElementById('modal__body-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.

Better use camel case notation for ID, and BEM notation for classes

Comment thread src/js/main.js
postsURL
.then(response => response.json())
.then(data => {
data.forEach(post => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Better use map() method instead of forEach()

Comment thread src/js/main.js
commentBox.removeChild(commentBox.lastChild);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't delete your comments! Use them to organize and give titles to each section of your code :)

Comment thread src/js/main.js
Comment on lines +17 to +34
const mainContainer = document.getElementById('cards-container');
const cardContainer = document.createElement('div');
cardContainer.classList.add('card', 'container__card--post');
const cardBody = document.createElement('div');
cardBody.classList.add('card-body');
const cardTitle = document.createElement('h5');
cardTitle.classList.add('card-title');
const titleLink = document.createElement('a');
titleLink.classList.add('card__title--post')
titleLink.setAttribute('href','javaScript:void(0)')
titleLink.setAttribute('data-bs-toggle', 'modal')
titleLink.setAttribute('data-bs-target', '#exampleModal')
titleLink.textContent = post.title.charAt(0).toUpperCase() + post.title.slice(1);
const delIcon = document.createElement('i');
const cardText = document.createElement('p');
const addIcon = document.createElement('i');
cardText.classList.add('card-text');
cardText.textContent = (post.body.charAt(0).toUpperCase() + post.body.slice(1)).slice(0, 80) + '...';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to put all your const "variables" together for better organisation.

Comment thread src/js/main.js
});
})
.catch(error => {
console.log(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remeber to get rid of all the console.log's

@jose-cuevas jose-cuevas 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.

Clean code, easy to read to it, congrats!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants