Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!DOCTYPE html>
        <h1>The Joy of Programming</h1>
          This is an example of formatting a blog-type website with Javascript; complete with "like" and commenting capabilities.
		<h4>Blog Post 1</h4>
			  Bacon ipsum dolor amet mollit bresaola brisket rump, irure quis anim ea fatback deserunt swine jerky. Nostrud ball tip bresaola short loin veniam, shank do id capicola qui beef ribs. Pork chop sausage cillum magna, ullamco pig hamburger. Cupidatat burgdoggen qui jerky est sirloin. Quis voluptate kielbasa mollit.
Strip steak voluptate biltong ground round, landjaeger short loin salami buffalo cow dolor. Aliqua pork belly aliquip beef sirloin, fatback commodo burgdoggen strip steak in velit. Biltong do bacon, boudin leberkas beef porchetta eu culpa brisket fugiat ex. Pork belly chuck ea do, fugiat ham consectetur tri-tip shankle turkey cupidatat. Alcatra beef commodo, fugiat exercitation anim short ribs kevin ad frankfurter. Chicken frankfurter pastrami pork chop.
      <div class="like">
         <a href="#" class="like-link"> 🚀</a>
			<span id="likeCount" class="like-count"></span>
      <div id="comments" class="comments">
      <form id="new-comment">
        <textarea id="new-comment-body" class="new-comment" placeholder="Spicy jalapeno bacon ipsum dolor amet duis anim minim shank pork spare ribs corned beef. Fatback elit in shankle ea sed frankfurter irure exercitation cow kevin. Flank occaecat rump frankfurter ipsum doner duis kevin ut drumstick do. Officia fugiat do reprehenderit ribeye."></textarea>
        <button type="submit" class="submit">Submit</button>

              html {
	margin: 50px;
	font-family: Avenir;

.like-link {
	font-size: 25px;

.like-count {
	font-size: 20px;
	font-family: Courier;

a {
	text-decoration: none;

.comments {
	margin-top: 25px;

.comment {
	margin-bottom: 25px;
	border-bottom: 1px solid slategray;

.new-comment {
	width: 100%;
	height: 100px;
	padding: 5px;
	font-size: 14px;
	line-height: 1.1;

.submit {
	color: darkred;
	cursor: pointer;
	height: 25px;
	width: 150px;
	background-color: #efefef;
	border: 1px solid white;
  	box-shadow: 2px 2px lightgray;
	font-family: Courier;
	font-size: 14px;
              var link = document.querySelector('.like-link');
var count = document.querySelector('#likeCount');
var form = document.querySelector('#new-comment');
var body = document.querySelector('#new-comment-body');
var comments = document.querySelector('#comments');
var parseStoredLikes = JSON.parse(localStorage.getItem('likes')) || [];
count.textContent = parseStoredLikes.length;
var parseStoredComments = JSON.parse(localStorage.getItem('comments')) || [];

function like(event) {
  var parsedContent = parseInt(count.textContent);
  count.textContent = parsedContent + 1;
  var likeCount = {
  localStorage.setItem('likes', JSON.stringify(parseStoredLikes));

function comment(e) {
    var commentText = (this.querySelector('#new-comment-body')).value;
    var commentObj = {
        deleted: false
    populateComments(parseStoredComments, comments);
    localStorage.setItem('comments', JSON.stringify(parseStoredComments));

function populateComments(commentArray = [], commentList) {
    commentList.innerHTML = commentArray.map((commentObj, i) => {
    return `
		<span class="quotes" style="color:slategray;font-size:20px;">❝</span><span id="${i}" onclick="deleteComment(id);" style="float:right;cursor:pointer;color:red;font-size:12px;">delete</span>
        <div data-index=${i} id="comment${i}" class='comment'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${commentObj.commentText}</div>

function deleteComment(id) {
    var i = parseInt(id);
    parseStoredComments[i].deleted = !parseStoredComments[i].deleted;
    localStorage.setItem('comments', JSON.stringify(parseStoredComments));
    populateComments(parseStoredComments, comments);

link.addEventListener('click', like);
form.addEventListener('submit', comment);

populateComments(parseStoredComments, comments);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.