Skip to content
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
96 changes: 78 additions & 18 deletions components/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,91 @@ const data = [
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: 'BloomTech Students: "I am the best!"',
date: 'Nov 5th, 2018',
firstParagraph: `Lucas ipsum dolor sit amet ben twi'lek padmé darth darth darth moff hutt organa twi'lek. Ben amidala secura skywalker lando
moff wicket tatooine luke.Solo wampa wampa calrissian yoda moff.Darth grievous darth gonk darth hutt.Darth baba skywalker
watto fett jango maul han.Mon ewok sidious sidious lando kenobi grievous gamorrean solo.Yoda wedge utapau darth calamari.
Hutt calamari darth jabba.Darth dooku amidala organa moff.Boba darth binks solo hutt skywalker dantooine skywalker.Qui - gonn
jar twi'lek jinn leia jango skywalker mon.`,

secondParagraph: `Grievous fett calamari anakin skywalker hutt.Alderaan darth kenobi darth r2- d2
windu mothma.Sidious darth calamari moff.Wampa mothma sith wedge solo mara.Darth gonk maul sith moff chewbacca palpatine
mace amidala.C - 3po solo skywalker anakin yoda leia.Maul wampa bespin watto jade ewok darth jabba.Lando dantooine moff
k - 3po dantooine luke.Fisto mandalore darth wedge c - 3p0 ahsoka.Secura moff palpatine fett.Anakin sith darth darth.Moff
solo leia ben ponda jade.Binks jango aayla skywalker skywalker cade.Mustafar darth ventress anakin watto.Yavin jawa sebulba
owen jinn tatooine sith organa.`,

thirdParagraph: `Dagobah hutt jawa leia calamari ventress skywalker yoda. Binks wicket hutt coruscant sidious
naboo ackbar tatooine. Hutt lars padmé darth. Maul solo darth darth jabba qui-gon chewbacca darth maul. Moff baba wicket
han. C-3po antilles moff qui-gon ahsoka aayla dooku amidala. Palpatine droid amidala droid k-3po twi'lek padmé wookiee. Leia
moff calamari mon obi-wan. Solo grievous lando coruscant. Jinn darth palpatine obi-wan mon.`
}
];

/*
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:
function articleMaker(obj){
const article = document.createElement('div');
const title = document.createElement('h2');
const date = document.createElement('p');
const firstParagraph = document.createElement('p');
const secondParagraph = document.createElement('p');
const thirdParagraph = document.createElement('p');
const expandButton = document.createElement('span');

article.appendChild(title);
article.appendChild(date)
article.appendChild(firstParagraph);
article.appendChild(secondParagraph);
article.appendChild(thirdParagraph);
article.appendChild(expandButton);

article.classList.add('article')
date.classList.add('date')
firstParagraph.classList.add('date')
secondParagraph.classList.add('date')
thirdParagraph.classList.add('date')
expandButton.classList.add('expandButton')

title.textContent = obj.title;
date.textContent = obj.date;
firstParagraph.textContent = obj.firstParagraph;
secondParagraph.textContent = obj.secondParagraph;
thirdParagraph.textContent = obj.thirdParagraph;
expandButton.textContent = '+';

expandButton.addEventListener('click', function(){
article.classList.toggle('article-open')
})

return article;
}

data.forEach(article =>{
document.querySelector('div.articles').appendChild(articleMaker(article))
})
// <div class="article">
// <h2>{title of the article}</h2>
// <p class="date">{date of the article}</p>

// {three separate paragraph elements}

{three separate paragraph elements}
// <span class="expandButton">+</span>
// </div>

<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.
*/
28 changes: 28 additions & 0 deletions components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let menuItems = [
'Log Out'
];


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

Expand All @@ -31,3 +32,30 @@ let menuItems = [

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

function menuMaker(array){
const menu = document.createElement('div');
const ul = document.createElement('ul');


array.forEach(element =>{
const li = document.createElement('li');
li.textContent = element;
ul.appendChild(li);
})

menu.classList.add('menu');
menu.appendChild(ul);

const menuButton = document.querySelector('.menu-button')

menuButton.addEventListener('click', function(){
menu.classList.toggle('menu--open')
})
return menu;
}

const menuElements = menuMaker(menuItems);
const header = document.querySelector('.header');

header.appendChild(menuElements);
Loading