Skip to content
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

finished #1253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 71 additions & 18 deletions components/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,87 @@ const data = [
hodor, hodor hodor, hodor, hodor hodor. Hodor hodor - hodor - hodor... Hodor hodor hodor hodor hodor hodor hodor?! Hodor
hodor - hodor hodor hodor. Hodor. Hodor hodor... Hodor hodor hodor hodor hodor? `,

thirdParagraph: `Hodor hodor - hodor... Hodor hodor hodor hodor. Hodor. Hodor! Hodor hodor, hodor hodor hodor hodor hodor; hodor hodor? Hodor!
Hodor hodor, HODOR hodor, hodor hodor?! Hodor! Hodor hodor, HODOR hodor, hodor hodor, hodor, hodor hodor. Hodor, hodor.
Hodor. Hodor, hodor, hodor. Hodor hodor... Hodor hodor hodor?! Hodor, hodor... Hodor hodor HODOR hodor, hodor hodor. Hodor.`
},
{
title: 'Wow what a story mark',
date: 'Jan 1st, 2019',
firstParagraph: `Hodor hodor HODOR! Hodor hodor - hodor, hodor. Hodor hodor... Hodor hodor hodor; hodor hodor. Hodor hodor hodor, hodor, hodor
hodor. Hodor, hodor. Hodor. Hodor, hodor - hodor... Hodor hodor hodor; hodor HODOR hodor, hodor hodor?! Hodor hodor, hodor.
Hodor hodor hodor hodor hodor! Hodor hodor - HODOR hodor, hodor hodor hodor hodor hodor; hodor hodor? `,

secondParagraph: `Hodor, hodor. Hodor. Hodor, hodor, hodor. Hodor hodor, hodor. Hodor hodor, hodor, hodor hodor. Hodor! Hodor hodor, hodor;
hodor hodor hodor? Hodor, hodor. Hodor. Hodor, hodor - HODOR hodor, hodor hodor hodor! Hodor, hodor. Hodor. Hodor, HODOR
hodor, hodor hodor, hodor, hodor hodor. Hodor hodor - hodor - hodor... Hodor hodor hodor hodor hodor hodor hodor?! Hodor
hodor - hodor hodor hodor. Hodor. Hodor hodor... Hodor hodor hodor hodor hodor? `,

thirdParagraph: `Hodor hodor - hodor... Hodor hodor hodor hodor. Hodor. Hodor! Hodor hodor, hodor hodor hodor hodor hodor; hodor hodor? Hodor!
Hodor hodor, HODOR hodor, hodor hodor?! Hodor! Hodor hodor, HODOR hodor, hodor hodor, hodor, hodor hodor. Hodor, hodor.
Hodor. Hodor, hodor, hodor. Hodor hodor... Hodor hodor hodor?! Hodor, hodor... Hodor hodor HODOR hodor, hodor hodor. Hodor.`
}
];

/*
Step 1: Write a component called 'articleMaker' to create an article.
Your component is a function that takes an article object as its only argument,
and returns a DOM node looking like the one below:

<div class="article">
<h2>{title of the article}</h2>
<p class="date">{date of the article}</p>
// Step 1: Write a component called 'articleMaker' to create an article.
// Your component is a function that takes an article object as its only argument,
// and returns a DOM node looking like the one below:

// <div class="article">
// <h2>{title of the article}</h2>
// <p class="date">{date of the article}</p>

// {three separate paragraph elements}

// <span class="expandButton">+</span>
// </div>
function articleMaker(obj){
const article = document.createElement('div');
const articleTitle = document.createElement('h2');
const articleDate = document.createElement('p');
const articlePara1 = document.createElement('p');
const articlePara2 = document.createElement('p');
const articlePara3 = document.createElement('p');
const expandButton = document.createElement('span');

article.classList.add('article');
articleDate.classList.add('date');
expandButton.classList.add('expandButton');

article.appendChild(articleTitle);
article.appendChild(articleDate)
article.appendChild(articlePara1)
article.appendChild(articlePara2)
article.appendChild(articlePara3)
article.appendChild(expandButton)

articleTitle.textContent = obj.title;
articleDate.textContent = obj.date;
articlePara1.textContent = obj.firstParagraph;
articlePara2.textContent = obj.secondParagraph;
articlePara3.textContent = obj.thirdParagraph;
expandButton.textContent = '+';

// console.log(article)
expandButton.addEventListener('click', () => {
article.classList.toggle('article-open')
})
return article
}

{three separate paragraph elements}
data.forEach(article => {
document.querySelector('div.articles').appendChild(articleMaker(article))
})

<span class="expandButton">+</span>
</div>
// Step 2: Still inside `articleMaker`, add an event listener to the span.expandButton.
// This listener should toggle the class 'article-open' on div.article.

Step 2: Still inside `articleMaker`, add an event listener to the span.expandButton.
This listener should toggle the class 'article-open' on div.article.
// Step 3: Don't forget to return something from your function!

Step 3: Don't forget to return something from your function!
// Step 4: Outside your function now, loop over the data. At each iteration you'll use your component
// to create a div.article element and append it to the DOM inside div.articles (see index.html).

Step 4: Outside your function now, loop over the data. At each iteration you'll use your component
to create a div.article element and append it to the DOM inside div.articles (see index.html).
// Step 5: Try adding new article object to the data array. Make sure it is in the same format as the others.
// Refresh the page to see the new article.

Step 5: Try adding new article object to the data array. Make sure it is in the same format as the others.
Refresh the page to see the new article.
*/
54 changes: 39 additions & 15 deletions components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,49 @@ let menuItems = [
'Log Out'
];

/*
Step 1: Write a component called 'menuMaker' to create a menu like the markup below:

<div class="menu">
<ul>
{each menu item as an <li>}
</ul>
</div>
// Step 1: Write a component called 'menuMaker' to create a menu like the markup below:

The 'menuMaker' takes an array of menu items as its only argument.
// <div class="menu">
// <ul>
// {each menu item as an <li>}
// </ul>
// </div>

Step 2: Inside the function, iterate over the array creating a list item <li> element for each item in the array.
Add those items to the <ul>
// The 'menuMaker' takes an array of menu items as its only argument.
function menuMaker(linksArray){
const menuWrapper = document.createElement('div')
const menuList = document.createElement('ul')

Step 3: Still inside your function, select from the DOM the menu button (the element with a class of 'menu-button').
menuWrapper.appendChild(menuList);

Step 4: Add a click event listener to the menu button. When clicked it should toggle the class 'menu--open' on div.menu (your div with a 'menu' class).
menuWrapper.classList.add('menu');

Step 5: Don't forget to return your div.menu.
linksArray.forEach(linkText => {
const link = document.createElement('li');
link.textConent = linkText
menuList.appendChild(link);
})
const hanMenu = document.querySelector('.menu-button');
hanMenu.addEventListener('click', () => {
menuWrapper.classList.toggle('menu--open')
})

return menuWrapper
}

// console.log(menuMaker(menuItems))

document.querySelector('.header').appendChild(menuMaker(menuItems))

// Step 2: Inside the function, iterate over the array creating a list item <li> element for each item in the array.
// Add those items to the <ul>

// Step 3: Still inside your function, select from the DOM the menu button (the element with a class of 'menu-button').

// Step 4: Add a click event listener to the menu button. When clicked it should toggle the class 'menu--open' on div.menu (your div with a 'menu' class).

// Step 5: Don't forget to return your div.menu.

// Step 6: Use 'menuMaker' to create a menu using the 'menuItems' array, and append the returned menu to the header.

Step 6: Use 'menuMaker' to create a menu using the 'menuItems' array, and append the returned menu to the header.
*/
Loading