Javascript excels in building robust web applications using CSS and HTML. Anyone can work on JavaScript projects, even with basic programming skills. However, choosing a Javascript project can sometimes take time, depending on your proficiency level.
To overcome this problem, we have listed some of the best JavaScript projects in this article that you can develop and add to your portfolio.
Top JavaScript Projects to Develop
This section will explain various JavaScript projects with their source code, which will help you understand everything easily.
1. Hex Color Application
Hex color is a six-digit code of the color that you can use to create color. So the application efficiently changes the background color when you press a single button.
It also displays the hexadecimal value for more clarity. The objective of this project is to generate a random hex color and, after doing so, set it as the background color. Here is the exemplary source code:
<!DOCTYPE html> <html> <head> <title>Choose A Color</title> <style> body { margin: 2; padding: 2; display: grid; place-items: center; height: 50vh; font-size: 20px; } .main { height: 200px; width: 550px; background: #FFC90e; border-radius: 5px; display: grid; place-items: center; color: #00000; font-family: Impact; border-radius: 25px; } #colorPicker { background-color: none; outline: none; border: none; height: 80px; width: 80px; cursor: pointer; } #box { outline: none; border: 4px solid #000; border-radius: 30px; height: 25px; width: 90px; padding: 0 10px; } </style> </head> <body> <h1>Choose A Color</h1> <div class="main"> Color Picker: <input type="color" id="colorPicker" value="#35cdde"> Enter Hex Code: <input type="text" id="box"> </div> <script> function myColor() { var color = document.getElementById('colorPicker').value; document.body.style.backgroundColor = color; document.getElementById('box').value = color; } document.getElementById('colorPicker') .addEventListener('input', myColor); </script> </body> </html>
2. Random Quote Generator
In this JavaScript project, you must build an app that displays famous random quotes every time the user clicks a button. To build this project, you need knowledge of basic JavaScript concepts like object literals, loops, and variables.
By working on a JavaScript project like the Random Quote Generator, you’ll be able to practice your JavaScript skills in an effective and fun way. Plus, it can be a small portfolio addition to help showcase your JavaScript knowledge to recruiters.
You can use the following source code as an example to create a random quote generator:
HTML Code
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"/> </head> <body id="body"> <div> <div class="block text-center"> <div class = "quote-box block__main block__front"> <span class = "quote"> <i class="fas fa-2x fa-quote-left"></i> <span class = "text"> </span> </span> <div class = "author"> </div> <a class = "new-quote btn btn-default" onclick="newQuote()">New Quote</a> </div> <div class = "quote-box block__main block__back"> <span class = "quote"> <i class="fas fa-2x fa-quote-left"></i> <span class = "text"> </span> </span> <div class = "author"> </div> <a class = "new-quote btn btn-default " onclick="newQuote()">New Quote</a> </div> </div> </div> <script src="script.js"></script> </body> </html>
CSS Code
*{ margin:0; padding:0; box-sizing: border-box; } body{ min-height:100vh; transition: 0.5s; transition-timing-function: ease-in-out; background-image: linear-gradient(to right bottom, #ffc90e, #ff0101a8); } .quote-box{ padding:3rem; transition: 0.5s; transition-timing-function: ease-in-out; } .text{ font-size:30px; padding-left:10px; transition: 0.5s; transition-timing-function: ease-in; font-family: 'Lucida Handwriting', cursive; background-image: linear-gradient(to right bottom, #000000, #000000); color: transparent; -webkit-background-clip: text; } .quote{ transition: 0.35s; transition-timing-function: ease-in-out; } .new-quote{ font-size:20px; border-radius: 2px; cursor:pointer; padding-bottom: 10px; padding-top: 10px; margin-top: 15px; background-image: linear-gradient(to right bottom, #ffc90e, #900303ad); } .text-center{ text-align: center; } .new-quote:hover{ opacity: 0.8; } .author{ margin:25px; font-size:25 px; transition: 0.3s; transition-timing-function: ease-in-out; font-family: 'Calibri'; background-image: linear-gradient(to right bottom, #000000,#000000 ); color: transparent; -webkit-background-clip: text; } p{ margin-top: 10px; text-align: center; position: absolute; width: 100%; top:21.5%; } .block { perspective: 150rem; position: absolute; top:25%; left: 27%; } .block__main { min-width: 45vw; position: absolute; transition: all .8s ease; backface-visibility: hidden; box-shadow: 0rem 1.5rem 4rem rgba(0, 0, 0, 0.15); border-radius: .5rem; background-image: linear-gradient(to right bottom, #ffffff,#ffffff); } .block__back { transform: rotateY(180deg); } .rotateF{ transform: rotateY(-180deg); } .rotateB{ transform: rotate(0deg); }
JS Code
var data; let front = true; const authors = document.querySelectorAll(".author"); const texts = document.querySelectorAll(".text"); const body = document.getElementById("body"); const button = document.querySelectorAll(".new-quote"); const blockFront = document.querySelector(".block__front"); const blockBack = document.querySelector(".block__back"); const authorFront = authors[0]; const authorBack = authors[1]; const textFront = texts[0]; const textBack = texts[1]; const buttonFront = button[0]; const buttonBack = button[1]; const displayQuote = () =>{ let index = Math.floor(Math.random()*data.length); let quote = data[index].text; let author = data[index].author; if(!author){ author = "Anonymous" } if(front){ textFront.innerHTML = quote; authorFront.innerHTML = author; }else{ textBack.innerHTML = quote; authorBack.innerHTML = author; } front = !front; } fetch("https://type.fit/api/quotes") .then(function(response) { return response.json(); }) .then(function(data) { this.data = data; displayQuote() }); function newQuote(){ blockBack.classList.toggle('rotateB'); blockFront.classList.toggle('rotateF'); displayQuote(); }
3. JavaScript Calculator
The idea of this project is to create a classic calculator. You can create a nice-looking, functional calculator using CSS for beautification and HTML for creating the structure of the calculator.
The performance and function of the buttons on the calculators require the use of JavaScript. In the calculator, you can add basic functions like multiplication, division, addition, and so on, as well as the functions of a scientific calculator.
<!DOCTYPE html> <html lang = "en"> <head> <style> h1 { text-align: center; padding: 30px; background-color: #ffc90e; color: #00000; } #clear{ width: 360px; border: 1px solid black; padding: 12px; background-color:#ffc90e; } .formstyle { width: 380px; height: 700px; margin: auto; border: 1px solid black; border-radius: 5px; padding: 10px; } input { width: 80px; background-color: #ffc90e; color: black; border: 1px solid black; border-radius: 5px; padding: 26px; margin: 5px; font-size: 40px; } #calc{ width: 324px; border: 1px solid black; border-radius: 3px; padding: 20px; margin: auto; } </style> </head> <body> <div class= "formstyle"> <form name = "form1"> <input id = "calc" type ="text" name = "answer"> <br> <br> <input type = "button" value = "1" onclick = "form1.answer.value += '1' "> <input type = "button" value = "2" onclick = "form1.answer.value += '2' "> <input type = "button" value = "3" onclick = "form1.answer.value += '3' "> <input type = "button" value = "+" onclick = "form1.answer.value += '+' "> <br> <br> <input type = "button" value = "4" onclick = "form1.answer.value += '4' "> <input type = "button" value = "5" onclick = "form1.answer.value += '5' "> <input type = "button" value = "6" onclick = "form1.answer.value += '6' "> <input type = "button" value = "-" onclick = "form1.answer.value += '-' "> <br> <br> <input type = "button" value = "7" onclick = "form1.answer.value += '7' "> <input type = "button" value = "8" onclick = "form1.answer.value += '8' "> <input type = "button" value = "9" onclick = "form1.answer.value += '9' "> <input type = "button" value = "*" onclick = "form1.answer.value += '*' "> <br> <br> <input type = "button" value = "/" onclick = "form1.answer.value += '/' "> <input type = "button" value = "0" onclick = "form1.answer.value += '0' "> <input type = "button" value = "." onclick = "form1.answer.value += '.' "> <input type = "button" value = "=" onclick = "form1.answer.value = eval(form1.answer.value) "> <br> <input type = "button" value = "CLEAR" onclick = "form1.answer.value = ' ' " id= "clear" > <br> </form> </div> </body> </html>
4. Animated Counter
A simple animated counter to display a counter starting from zero to infinite. Many websites use this type of counter to make their web pages attractive and amazing.
Hence, it is good to create animated counters using various JS concepts. For example:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <style> canvas { border:2px solid #000000; background-color: #ffffff; } </style> </head> <body onload="startGame()"> <script> var myGamePiece; var myObstacles = []; var myScore; function startGame() { myGamePiece = new component(25, 25, "yellow", 10, 100); myGamePiece.gravity = 0.05; myScore = new component("20px", "Impact", "red", 200, 50, "text"); myGameArea.start(); } var myGameArea = { canvas : document.createElement("canvas"), start : function() { this.canvas.width = 600; this.canvas.height = 400; this.context = this.canvas.getContext("2d"); document.body.insertBefore(this.canvas, document.body.childNodes[0]); this.frameNo = 0; this.interval = setInterval(updateGameArea, 20); }, clear : function() { this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); } } function component(width, height, color, x, y, type) { this.type = type; this.score = 0; this.width = width; this.height = height; this.speedX = 0; this.speedY = 0; this.x = x; this.y = y; this.gravity = 0; this.gravitySpeed = 0; this.update = function() { ctx = myGameArea.context; if (this.type == "text") { ctx.font = this.width + " " + this.height; ctx.fillStyle = color; ctx.fillText(this.text, this.x, this.y); } else { ctx.fillStyle = color; ctx.fillRect(this.x, this.y, this.width, this.height); } } this.newPos = function() { this.gravitySpeed += this.gravity; this.x += this.speedX; this.y += this.speedY + this.gravitySpeed; this.hitBottom(); } this.hitBottom = function() { var rockbottom = myGameArea.canvas.height - this.height; if (this.y > rockbottom) { this.y = rockbottom; this.gravitySpeed = 0; } } this.crashWith = function(otherobj) { var myleft = this.x; var myright = this.x + (this.width); var mytop = this.y; var mybottom = this.y + (this.height); var otherleft = otherobj.x; var otherright = otherobj.x + (otherobj.width); var othertop = otherobj.y; var otherbottom = otherobj.y + (otherobj.height); var crash = true; if ((mybottom < othertop) || (mytop > otherbottom) || (myright < otherleft) || (myleft > otherright)) { crash = false; } return crash; } } function updateGameArea() { var x, height, gap, minHeight, maxHeight, minGap, maxGap; for (i = 0; i < myObstacles.length; i += 1) { if (myGamePiece.crashWith(myObstacles[i])) { return; } } myGameArea.clear(); myGameArea.frameNo += 1; if (myGameArea.frameNo == 1 || everyinterval(150)) { x = myGameArea.canvas.width; minHeight = 20; maxHeight = 200; height = Math.floor(Math.random()*(maxHeight-minHeight+1)+minHeight); minGap = 50; maxGap = 200; gap = Math.floor(Math.random()*(maxGap-minGap+1)+minGap); myObstacles.push(new component(20, height, "black", x, 0)); myObstacles.push(new component(20, x - height - gap, "black", x, height + gap)); } for (i = 0; i < myObstacles.length; i += 1) { myObstacles[i].x += -1; myObstacles[i].update(); } myScore.text="SCORE: " + myGameArea.frameNo; myScore.update(); myGamePiece.newPos(); myGamePiece.update(); } function everyinterval(n) { if ((myGameArea.frameNo / n) % 1 == 0) {return true;} return false; } function accelerate(n) { myGamePiece.gravity = n; } </script> <br> <button onmousedown="accelerate(-0.2)" onmouseup="accelerate(0.05)">UP</button> <p>Press the UP button</p> </body> </html>
5. To-Do List
A to-do list is handy when storing important information and holding things on track. You can also create an interactive to-do list using JavaScript codes. It requires simple codes, but it definitely impacts your technical skills positively. Here is the example source code you can try to create a to-do list using JavaScript codes:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { margin: 0; min-width: 145px; } * { box-sizing: border-box; } ul { margin: 0; padding: 0; } ul li { cursor: pointer; position: relative; padding: 20px 10px 20px 10px; list-style-type: none; background: #ffc90e; font-size: 20px; transition: 0.2s; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } ul li:nth-child(odd) { background: #e6b200; } ul li:hover { background: #ffffff; } ul li.checked { background: #000000; color: #ffffff; text-decoration: line-through; } ul li.checked::before { content: ''; position: absolute; border-color: #000000; border-style: solid; border-width: 1 1px 1px 1; top: 5px; left: 10px; transform: rotate(45deg); height: 10px; width: 10px; } .close { position: absolute; right: 0; top: 0; padding: 20px 15px 20px 10px; } .close:hover { background-color: #000000; color: white; } .header { background-color: #07ab77; padding: 25px 50px; color: white; text-align: center; } .header:after { content: ""; display: table; clear: both; } input { margin: 0; border: none; border-radius: 10; width: 75%; padding: 20px; float: left; font-size: 20px; } .addBtn { padding: 20px; width: 25%; background: #ffc90e; color: #000000; float: left; text-align: center; font-size: 20px; cursor: pointer; transition: 0.3s; border-radius: 0; } .addBtn:hover { background-color: #bbb; } </style> </head> <body> <div id="myDIV" class="header"> <h2 style="margin:10px">TO-DO LIST</h2> <input type="text" id="myInput" placeholder="Title..."> <span onclick="newElement()" class="addBtn">Add</span> </div> <ul id="myUL"> <li>Submit the pending assignment</li> <li class="checked">Request for payment release</li> <li>Meeting</li> <li>Research about trending topics</li> <li>Process the pending payments</li> </ul> <script> var myNodelist = document.getElementsByTagName("LI"); var i; for (i = 0; i < myNodelist.length; i++) { var span = document.createElement("SPAN"); var txt = document.createTextNode("\u00D7"); span.className = "close"; span.appendChild(txt); myNodelist[i].appendChild(span); } var close = document.getElementsByClassName("close"); var i; for (i = 0; i < close.length; i++) { close[i].onclick = function() { var div = this.parentElement; div.style.display = "none"; } } var list = document.querySelector('ul'); list.addEventListener('click', function(ev) { if (ev.target.tagName === 'LI') { ev.target.classList.toggle('checked'); } }, false); function newElement() { var li = document.createElement("li"); var inputValue = document.getElementById("myInput").value; var t = document.createTextNode(inputValue); li.appendChild(t); if (inputValue === '') { alert("You must write something!"); } else { document.getElementById("myUL").appendChild(li); } document.getElementById("myInput").value = ""; var span = document.createElement("SPAN"); var txt = document.createTextNode("\u00D7"); span.className = "close"; span.appendChild(txt); li.appendChild(span); for (i = 0; i < close.length; i++) { close[i].onclick = function() { var div = this.parentElement; div.style.display = "none"; } } } </script> </body> </html>
Final Thoughts
In the above article, we have included the best projects for JavaScript. In this article, we have categorized JavaScript projects for beginner, intermediate, and advanced JavaScript programmers. Working on all the above tasks will enhance your JavaScript skills and benefit your portfolio.
We hope the list of all the JavaScript projects included in the above list will help you. Apart from this, you can improve your knowledge of JavaScript by taking one of the best JavaScript courses.
Aditya is a seasoned JavaScript developer with extensive experience in MEAN stack development. He also has solid knowledge of various programming tools and technologies, including .NET and Java. His hobbies include reading comics, playing games, and camping.