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>
<html lang="en">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=divice-width, initial-scale=1.0">
	<meta http-equive="X-UA-Compatible" content="ie-edge">
	<link rel="stylesheet" href="">
	<link rel="stylesheet" href="" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
	<title>BookList App</title>
	<div class="container mt-4">
		<h1 class="display-4 text-center"><i class="fas fa-book-open text-primary"></i> <span class="text-secondary">Book</span> List</h1>
    <p class="text-center">Add your book information to store the it locally.</p>
		<form id="book-form">
			<div class="form-group">
				<label for="title">Title</label>
				<input type="text" id="title" class="form-control">
			<div class="form-group">
				<label for="author">Author</label>
				<input type="text" id="author" class="form-control">
			<div class="form-group">
				<label for="title">ISBN#</label>
				<input type="text" id="isbn" class="form-control">
			<input type="submit" value="Add Book" class="btn btn-primary btn-block">
		<table class="table table-striped mt-5">
			<tbody id="book-list"></tbody>
	<script src="app.js"></script>
              //Book Class
class Book{
	constructor( title, author, isbn ){
		this.title = title; = author;
		this.isbn = isbn;

//UI Class
class UI{
	static displayBooks(){
		const books = Store.getBooks();

		books.forEach((book) => UI.addBookToList(book));

	static addBookToList(book){
		const list = document.querySelector('#book-list');

		const row = document.createElement('tr');

		row.innerHTML = `
			<td><a href="#" class="btn btn-danger btn-sm delete">X</a></td>


	static deleteBook(el){
		if( el.classList.contains('delete')){

	static showAlert(message, className){
		const div = document.createElement('div');
		div.className = `alert alert-${className}`;
		const container = document.querySelector('.container');
		const form = document.querySelector('#book-form');
		container.insertBefore(div, form);
		//Vanish in 3 seconds
		setTimeout(() => document.querySelector('.alert').remove(), 3000);

	static clearFields(){
		document.querySelector('#title').value = '';
		document.querySelector('#author').value = '';
		document.querySelector('#isbn').value = '';

//Store Class
class Store{
	static getBooks(){
		let books;
		if( localStorage.getItem('books') == null ){
			books = [];
			books = JSON.parse(localStorage.getItem('books'));
		return books;
	static addBook(book){
		const books = Store.getBooks();
		localStorage.setItem('books', JSON.stringify(books));

	static removeBook(isbn){
		const books = Store.getBooks();
		books.forEach((book, index) => {
			if(book.isbn === isbn){
				books.splice(index, 1);

		localStorage.setItem('books', JSON.stringify(books));

//Event - Display Books
document.addEventListener('DOMContentLoaded', UI.displayBooks);

//Event - Add a Book
document.querySelector('#book-form').addEventListener('submit', (e)=>{
	//prevent submit
	//Get form values
	const title = document.querySelector('#title').value;
	const author = document.querySelector('#author').value;
	const isbn = document.querySelector('#isbn').value;

	if( title === '' || author === '' || isbn ==='' ){
		UI.showAlert('Please fill in all fields', 'danger');
		//Instantiate book
		const book = new Book(title, author, isbn);

		//Add book to UI

		//Add book to store

		//Success message
		UI.showAlert('Book added', 'success');

		//Clear fields


//Event - Remove a Book
document.querySelector('#book-list').addEventListener('click', (e) => {
	//Remove book from UI

	//Remove book from store

	//Show success message
	UI.showAlert('Book removed', 'success');

🕑 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.