Skip to content

Niyander Tech

Learn with fun

Menu
  • Home
  • Categories
    • Android
    • Alpine.js Components
    • Genshin Impact News
    • Jobs and Internship
    • Coursera Hub
  • Our Policies
    • Privacy Policy
    • Terms and Conditions
    • Contact Us
  • Coursera Search Engine
  • AI Tools
    • AI Background Remover
    • AI Video Downloader
    • 98+ Beautiful CSS Box-Shadow
    • G-Drive Download Link Generator
Menu
Create Beautiful Love Calculator using JavaScript & Bootstrap 5

How to Create a Beautiful Love Calculator Using JavaScript

Posted on December 12, 2021September 6, 2024 by Niyander

Hello friends! In this article, I’m excited to share how you can build a charming Love Calculator using JavaScript. This project will help you learn how to combine HTML, CSS, and JavaScript to create an engaging web application. / How to Create a Beautiful Love Calculator Using JavaScript

Introduction

Creating a Love Calculator is a fun way to enhance your web development skills. This project involves building a simple web app that calculates a love percentage based on user input. With basic knowledge of HTML, CSS, and JavaScript, you’ll be able to create a visually appealing and functional application.

Demo and Source Code / You can see a live demo of the Love Calculator here:
See Demo

Download Full Source Code / For the full source code, visit the following links:
View Full Source Code

 

Building the Love Calculator

Step 1: Create the Basic HTML Template
Start by creating a basic HTML template. Save this file as index.html.

<!DOCTYPE html>
<html>
<head>
<title>Love Calculator</title>
</head>
<body>
<h1>Love Calculator</h1>
<p>This is a paragraph.</p>
</body>
</html>

 

Step 2: Add CDN Links for Styling
Enhance the appearance of your application by including Bootstrap 5 and Google Fonts CDN links in the <head> section of your HTML.

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

<!-- Google Fonts CSS -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa&display=swap" rel="stylesheet">

 

Step 3: Update the HTML Body
Replace the content inside the <body> tag with the following code. This code creates a simple card layout for your Love Calculator.

<div class="cont">
<div class="row">
<div class="col-md-6">
<div class="d-none d-md-block">
<img src="love1.jpg" class="ig"/>
</div>
</div>
<div class="col-md-6 col-lg-6">
<h2 style="color:pink;">Try the Love Calculator</h2>
<hr/>
<form method="POST" onclick="return false" id="myform">
<div class="form-group">
<label for="text">Your Name:</label>
<input type="text" class="form-control" id="fname" placeholder="Your name" name="fname" autocomplete="off">
</div>
<br/>
<div class="form-group">
<label for="text">Crush Name:</label>
<input type="text" class="form-control" id="sname" placeholder="Crush name" name="sname" autocomplete="off">
</div>
<br/>
<br/>
<button type="submit" class="btn btn btl" id="btn" onclick="checkLovePercentage()">Submit</button>
<br/><br/><br/>
<div class="form-group">
<h6 class="text-center" id="demp"> </h6>
<h2 class="text-center">Love Percentage</h2>
<h1 class="text-center"><span id="demo"></span></h1>
<span id="dem"></span>
</div>
<br/>
</form>
</div>
</div>
</div>

 

Step 4: Apply Custom CSS
Add the following CSS code within the <style> tags in the <head> section to style your Love Calculator.

<style>
body {
margin: 0;
padding: 0;
font-family: 'Comfortaa', cursive;
}
.row {
background-color: #ffffff;
margin-top: 5%;
border-radius: 4px;
box-shadow: 0 1px 1px 0 rgb(255,105,180), 0 6px 20px 0 rgb(255,192,203);
padding: 5%;
}
hr {
width: 80%;
align: left;
color: #e91e63;
}
#fname, #sname {
border: 1.2px solid pink;
border-radius: 4px;
}
.cont {
margin: auto;
width: 62%;
}
#demp {
margin-bottom: 15px;
}
@media only screen and (max-width: 600px) {
body {
margin: 0;
padding: 0;
}
.cont {
width: 82%;
}
}
.ig {
border-radius: 4px;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
width: 88%;
height: 500px;
}
.btl {
background-color: #ff9dbe;
border-color: #ff9dbe;
color: white;
}
.card {
width: 95%;
margin-top: 40px;
margin-bottom: 20px;
}
</style>

 

Step 5: Implement JavaScript Functionality
Add the following JavaScript code just before the closing </body> tag. This script calculates the love percentage and provides feedback based on the result.

<script>
function checkLovePercentage() {
var name = document.getElementById('fname').value;
var lname = document.getElementById('sname').value;
name = name.toLowerCase();
lname = lname.toLowerCase();

if (name === "") {
alert('Please Enter Your Name');
} else if (name.length <= 2) {
alert('Minimum length is 3 characters');
} else if (!isNaN(name)) {
alert('Numbers are not allowed in names');
} else if (lname === "") {
alert('Please Enter Your Crush Name');
} else if (lname.length <= 2) {
alert('Minimum length is 3 characters');
} else if (!isNaN(lname)) {
alert('Numbers are not allowed in names');
} else {
var loveData = Math.random() * 100;
loveData = Math.floor(loveData);
document.getElementById("demo").innerHTML = loveData + "%";

if (loveData >= 65) {
document.getElementById("demp").innerHTML = "<span style='background-color:#ff007f;color:white;display: inline-block; padding: 5px 10px; border-radius: 3px;'> " + name + " loves " + lname + "</span>";
document.getElementById("dem").innerHTML = "My favorite place in the world is by your side. My favorite distraction is you.";
}
}
}
</script>

 

Conclusion

Your Love Calculator is now ready! Refresh your HTML page, enter your name and your crush’s name, and click “Submit” to see the love percentage. This simple project combines HTML, CSS, and JavaScript to create an engaging and interactive web application. Feel free to customize and expand on this project as you see fit!

Follow me for more cool projects and tutorials.

 

 

Category: Bootstrap

Post navigation

← How to Create a Cat Fact Application Using a Free API
Activity Create a Product Backlog →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Notice

Hey guys! Need a Google Drive Direct Download Link Generator? I made a simple tool that does just that. 🚀
Convert any shared Drive link into a direct download link instantly.
Try it out now: https://niyander.com/projects/tools/gdrive/
Let me know your thoughts!

Notice

Hi everyone! I've built a collection of 98+ CSS Box-Shadow Examples for developers and designers! 🎨
Click on any card to copy the shadow — super handy for your projects.
Explore them all here: https://niyander.com/projects/tools/box-shadow/
Hope you find it useful!

Notice

Hey folks! Excited to share my new tool — an All-in-One Social Media Downloader! 📥
Download videos, photos, and audio from TikTok, YouTube, Instagram, Facebook, and more.
Check it out here: https://niyander.com/projects/tools/sm/
Your feedback is welcome!

Notice

Hey friends! I just launched a free AI Background Remover called Panda AI! 🐼
Easily remove backgrounds from images with just one click.
Try it out now: https://niyander.com/projects/tools/bg/
Let me know what you think!

May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Apr    

About

Greetings, Hey i am Niyander, and I hail from India, we strive to impart knowledge and offer assistance to those in need.

  • Alpine.js Components
  • Android
  • Bootstrap
  • Coursera Hub
  • Genshin Impact News
  • Jobs and Internship
  • Uncategorized

Hot Topics

  • Microsoft Azure Data Scientist Associate (DP-100) Quiz Answers + Review
  • Prepare for DP-100: Data Science on Microsoft Azure Exam Answers + Review
  • Genshin Impact Version 5.6 redeem codes
  • More Software Engineering Jobs in Japan for Expats – April 2025 Edition
© 2025 Niyander Tech | Powered by Minimalist Blog WordPress Theme