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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
31 changes: 31 additions & 0 deletions components/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,34 @@ const data = [
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.
*/
function articleMaker(obj){
const nDiv = document.createElement('div')
nDiv.classList.add('article')
const tit = document.createElement('h1')
tit.textContent = obj.title
nDiv.appendChild(tit)
const nDate = document.createElement('p')
nDate.textContent = obj.date
nDate.classList.add('date')
nDiv.appendChild(nDate)
const p1 = document.createElement('p')
const p2 = document.createElement('p')
const p3 = document.createElement('p')
p1.textContent = obj.firstParagraph
p2.textContent = obj.secondParagraph
p3.textContent = obj.thirdParagraph
nDiv.appendChild(p1)
nDiv.appendChild(p2)
nDiv.appendChild(p3)
const nSpan = document.createElement('span')
nSpan.textContent = '+'
nSpan.classList.add('expandButton')
nSpan.addEventListener('click', () =>{
nDiv.classList.toggle('article-open')
})
nDiv.appendChild(nSpan)
return nDiv
}
data.forEach(obj =>{
document.querySelector('div.articles').appendChild(articleMaker(obj))
})
14 changes: 14 additions & 0 deletions components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ let menuItems = [

Step 6: Use 'menuMaker' to create a menu using the 'menuItems' array, and append the returned menu to the header.
*/
function menuMaker(arr){
const nDiv = document.createElement('div')
nDiv.classList.add('menu')
const list = document.createElement('ul')
arr.forEach(item =>{
list.append(item)
})
nDiv.append(list)
document.querySelector('.menu-button').addEventListener('click', () =>{
document.querySelector('div.menu').classList.toggle('menu--open')
})
return nDiv
}
document.querySelector('.header').append(menuMaker(menuItems))
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<title>BloomTech Newsfeed</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./styles/index.less">
<link rel="stylesheet" href="./styles.css">
<script src="./components/Menu.js" defer></script>
<script src="./components/Article.js" defer></script>
</head>
Expand Down
Loading