Bootstrap

Create Beautiful Love Calculator using JavaScript & Bootstrap 5

In this article i am gone to share how you can Create Beautiful Love Calculator using JavaScript with you.. 

Visit This Link to See Demo 

To Build This Type of application You Need Some Basic knowledge just Like 

  1. HTML
  2. CSS,
  3. JavaScript

Follow My Steps to Create beautiful application like that

Step 1) First Create basic Html Template like that
<!DOCTYPE html>
<html>
  <head>
    <title>PageTitle</title>
  </head>
  <body>
    <h1>Love calculator</h1>
    <p>This is a paragraph.</p>
  </body>
</html>

 

Step 2) Use Some Basic CDN links to Make Page More attractive
in This i Use 2 CDN links
  • Bootstrap 5
  • Google Fonts

Copy this CDN links and Put on Head tag. / Bootstrap 5

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

Copy this CDN links and Put on Head tag. / Google Fonts

<!-- 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"> 

Now Our Html Page Look Cool

Step 3) Replace all the Code inside body from this Code..
In This Code i Created a Simple Card..
<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 Now Love beats</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="checkloveper()" >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">
        </div>
        <br/>
      </form>
    </div>
  </div>
</div>

Now Our Html Page Look Cool

Step 4) Add This Css Code Head Tag.
This Code make our card more attractive.
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%; } } /*space in nav bar*/ #sf{margin-right:9.5%; padding-left:5%; }
 li{padding-left:14px; padding-right:14px; font-style:bold; color:yellow; }
 /*image css*/ .ig{ border-radius: 4px; background-size: cover; background-repeat: no-repeat; background-position: center center; width:88%; height:500px; }
 /*button color*/ .btl{background-color:#ff9dbe; border-color:#ff9dbe; color:white; } .card{ width: 95%; margin-top:40px; margin-bottom:20px; }

Now Add JavaScript to do Some Cool Stuff.

Step 5) </span >Add This </span >JavaScript</span > Code in bottom of the HTML Page.
  • In This JavaScript code i take both input box name in variable to calculate love.
<script>
  function lovep(){
   var name = document.getElementById('fname').value;
   var lname = document.getElementById('sname').value;
   var name = name.toLowerCase();
   var lname = lname.toLowerCase();

  if(name == ""){
  alert('Please Enter Your Name');
  }else if (name.length <=2 ) {
       alert('Min lenght is 3')
         }else if(!isNaN(name)){
            alert('Numbers are Not allowed');
         }

    else if(lname == ""){
        alert('Please Enter Your Crush Name');
           }else if (lname.length <=2 ) {
              alert('Min lenght is 3')
               }else if(!isNaN(lname)){
                   alert('Numbers are Not allowed');
               }
    else{
         var lovdata = Math.random() * 100;
           lovdata = Math.floor(lovdata);
             document.getElementById("demo").innerHTML = lovdata + "%"; 
       }

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

    }
    else{

  }

  }
</script>

Now our Application is Ready. Refresh your Html Page and Enter your name or crush name to calculate love percentage. 
 
Follow me For this type of Cool Stuff.
 

IMPORTANT LINKS

 
See Demo App go to this Link:
Download Full Source code from this Link