Javascript Projects [Javascript Examples]
Why JavaScript Projects?
JS is the heart of any web application. Good knowledge of JavaScript can get you a range of challenging and interesting career options like developing mobile and desktop apps, building dynamic websites from scratch, UI/UX designer, or even a full stack developer.If you know the basics of JavaScript, projects are your next step to add stars to your resume.If you don’t have any prior programming experience, you can take up basic JavaScript courses and then come back to these projects.If you follow a bit of HTML & CSS, you will understand most of the Javascript projects with the source code mentioned below.
1. JavaScript Calculator
<html>
<body>
<div class = title >My Beautiful JS Calculator</div>
<table border=”2″>
<tr>
<td><input type=”button” value=”c” onclick=”clr()”/> </td>
<td colspan=”3″><input type=”text” id=”textval”/></td>
</tr>
<tr>
<td><input type=”button” value=”+” onclick=”display(‘+’)”/> </td>
<td><input type=”button” value=”1″ onclick=”display(‘1’)”/> </td>
<td><input type=”button” value=”2″ onclick=”display(‘2’)”/> </td>
<td><input type=”button” value=”3″ onclick=”display(‘3’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”-” onclick=”display(‘-‘)”/> </td>
<td><input type=”button” value=”4″ onclick=”display(‘4’)”/> </td>
<td><input type=”button” value=”5″ onclick=”display(‘5’)”/> </td>
<td><input type=”button” value=”6″ onclick=”display(‘6’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”*” onclick=”display(‘*’)”/> </td>
<td><input type=”button” value=”7″ onclick=”display(‘7’)”/> </td>
<td><input type=”button” value=”8″ onclick=”display(‘8’)”/> </td>
<td><input type=”button” value=”9″ onclick=”display(‘9’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”/” onclick=”display(‘/’)”/> </td>
<td><input type=”button” value=”.” onclick=”display(‘.’)”/> </td>
<td><input type=”button” value=”0″ onclick=”display(‘0’)”/> </td>
<td><input type=”button” value=”=” onclick=”evaluate()”/> </td>
</tr>
</table>
</body>
<script>
function display(val)
{
document.getElementById(“textval”).value+=val
}
function evaluate()
{
let x = document.getElementById(“textval”).value
let y = eval(x)
document.getElementById(“textval”).value = y
}
function clr()
{
document.getElementById(“textval”).value = “”
}
</script>
<style>
input[type=”button”]
{
border-radius: 10px;
background-color:blue;
color: white;
border-color:#black ;
width:100%;
}
input[type=”text”]
{
border-radius: 10px;
text-align: right;
background-color:black;
color: white;
border-color: white;
width:100%
}
</style>
</html>
2. Hangman Game
3. Tic Tac Toe Game
4. JavaScript Weather App
5. JavaScript Music Events
6. JavaScript Form Validation
<html>
<head>
<title>Form Validation</title>
<script type = “text/javascript”>
function validateEmail(emailField){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (reg.test(emailField.value) == false) {
alert(‘Invalid Email Address’);
return false;
}
return true;
}
function validate() {
var text;
if( document.myForm.name.value == “” ) {
text = “Name cannot be empty”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.name.focus() ;
return false;
}
if( document.myForm.email.value == “” ) {
text = “E-mail cannot be empty”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.email.focus() ;
return false;
}
var emailID = document.myForm.email.value;
atposn = emailID.indexOf(“@”);
dotposn = emailID.lastIndexOf(“.”);
if (atposn < 1 || ( dotposn – atposn < 2 )) {
text = “Please enter valid email ID”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.email.focus() ;
return false;
}
if( document.myForm.phone.value == “” || isNaN( document.myForm.phone.value ) ||
document.myForm.phone.value.length != 10 ) {
text = “Please enter a valid 10-digit phone number”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.phone.focus() ;
return false;
}
if( document.myForm.subject.value == “0” ) {
text = “Please provide your area of expertise”;
document.getElementById(“demo”).innerHTML = text;
return false;
}
return( true );
}
</script>
</head>
<body>
<form action = “” name = “myForm” onsubmit = “return(validate());”>
<h1 align=”center”>USER REGISTRATION</H1>
<table align=”center” cellspacing = “3” cellpadding = “3” border = “3”>
<tr>
<td align = “right”>Name</td>
<td><input type = “text” name = “name” /></td>
</tr>
<tr>
<td align = “right”>E-mail</td>
<td><input type = “text” name = “email” /></td>
</tr>
<tr>
<td align = “right”>Phone Number</td>
<td><input type = “text” name = “phone” /></td>
</tr>
<tr>
<td align = “right”>Subject</td>
<td>
<select name = “subject”>
<option value = “0” selected>Select</option>
<option value = “1”>HTML</option>
<option value = “2”>JavaScript</option>
<option value = “3”>CSS</option>
<option value = “4”>JSP</option>
</select>
</td>
</tr>
</table>
<p id=”demo” style=”color:red; text-align:center”></p>
<div style=”text-align:center”><input type = “submit” value = “Submit” /></div>
</form>
</body>
</html>
7. JavaScript Photo Details Display
8. Build an Interactive Landing Page
9. Build a Shopping Cart for Order Fulfillment
10. Single Page Application
Leave a Comment