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
43 changes: 43 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Page</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="style.css" rel="stylesheet">
</head>

<body>
<div class="container">
<header>
<h1>Reddit</h1>
</header>
</div>
<main class="container">
<hr>
<div class="comment-btns">
<span class="rm-comments-btn">remove</span>
<span class="show-comments-btn">comments:</span>
</div>
<span class="new-comments">I'm a comment - Posted By: Jeff
<br></span>
<div class="comment-btns">
<hr>
<span class="rm-comments-btn">remove</span>
<span class="show-comments-btn">comments:</span>
Comment on lines +28 to +29

Choose a reason for hiding this comment

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

same, could have been buttons

<button class="btn btn-danger btn-sm">Remove</button>
<button class="btn btn-info btn-sm">Show Comments</button>

</div>
<span class="new-comments">Here's a comment - Posted By: Jeff <br>
</span>
<hr>
<input class="post" type="text" placeholder="Post Text" />
<input class="name" type="text" placeholder="Your Name" />
<ul class="nav nav-pills">
<li role="presentation" class="active"><a href="#">Submit</a></li>
Comment on lines +36 to +37

Choose a reason for hiding this comment

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

never use ul or lists for buttons, use the button tag and you have 'btn btn-primary' bootstrap classes

</ul>
</main>
</body>
<script src="main.js"></script>

</html>
39 changes: 39 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const submitButton = document.getElementsByClassName('active')[0];

Choose a reason for hiding this comment

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

better to have consistency, either use getElementsByClassName or querySelector


submitButton.addEventListener('click', function () {

const inputPost = document.getElementsByClassName('post')[0].value;
const inputName = document.getElementsByClassName('name')[0].value;

const newSpan = document.createElement('span');
newSpan.innerHTML = `${inputPost}, posted by ${inputName}`;

Choose a reason for hiding this comment

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

this is less recommented, use textContent or appendChild as they are safer and more performant.

Comment on lines +4 to +9

Choose a reason for hiding this comment

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

your code alignment is off, check your lint settings. This affects readability.

const lineBreak = document.createElement('br');

const commentContainer = document.querySelector('.new-comments');
commentContainer.appendChild(newSpan);
commentContainer.appendChild(lineBreak);
});

const rmButton = document.getElementsByClassName('rm-comments-btn')[0];
rmButton.addEventListener('click', function () {
const commentsContainer = document.querySelector('.new-comments');
commentsContainer.innerHTML = '';
})

const toggleButtons = document.querySelectorAll('.show-comments-btn');

Choose a reason for hiding this comment

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

Suggested change


toggleButtons.forEach(button => {

Choose a reason for hiding this comment

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

this should have been a separate function with ternary operation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator

function toggleVisibility(element) {
  element.style.display = element.style.display === 'none' ? 'block' : 'none';
}

button.addEventListener('click', function () {

Choose a reason for hiding this comment

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

watch for too many empty spaces

const comments = this.parentElement.nextElementSibling;


Comment on lines +30 to +31

Choose a reason for hiding this comment

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

Suggested change

if (comments.style.display === 'none' || comments.style.display === '') {
comments.style.display = 'block';
} else {
comments.style.display = 'none';
}
});
});

49 changes: 49 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.container {
display: grid;
justify-content: center;
}

hr {
background-color: black;
color: black;
}

.rm-comments-btn {
background-color: blue;
border-radius: 5px;
padding: 2px;
font-size: 80%;
color: white;
}

.show-comments-btn {
margin-left: 5px;
background-color: blue;
border-radius: 5px;
padding: 2px;
font-size: 80%;
color: white;
}

input {
width: 400px;
margin: 5px;
}

hr {
width: 95%;
}

.active {
margin-left: 4px;
}

/* button {

Choose a reason for hiding this comment

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

do not push commented code

background-color: royalblue;
color: white;
border-radius: 5px;
margin-left: 7px;
width: 24%;
font-size:70%;
} */