Skip to content

Commit

Permalink
feature improved
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekkrjha2811 committed Jan 8, 2025
1 parent 89e57c7 commit 25053f5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 273 deletions.
2 changes: 1 addition & 1 deletion Calculators/Love-Calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The Love Calculator uses a basic algorithm to generate a love percentage. Here's

## ScreenShots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/142514166/36571c14-8080-404e-a81c-1bf0b6a5229a)
![image](c:\Users\abhis\OneDrive\Desktop\web\81.png)
50 changes: 32 additions & 18 deletions Calculators/Love-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,43 @@
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Love Calculator</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">

</head>

<body>
<div class="container">
<h2 id="title">Love Calculator</h2>
<label class="form-label">First Name</label>
<input type="text" class="form-control" id="name1" placeholder="Rahul" oninput="validateName('name1')" />

<label class="form-label">Second Name</label>
<input type="text" class="form-control" id="name2" placeholder="Anjali" oninput="validateName('name2')" />
<button type="button" id="btn">Calculate</button>
<p id="yourlovescoreis">Your love score is :</p>
<h1 id="score"></h1>
<button id="reload" onclick="reset()">&#128472;</button>
<div class="contentbox">
<h1><span>Love</span> Calculator</h1>
<p>Enter your name and your crush's name to see the chance that this relationship will work out: </p>

<div class="input-group">
<input type="text" required id="fname">
<span class="highlight"></span>
<span class="bar"></span>
<label>Your Name</label>
</div>

<div class="input-group">
<input type="text" required id="cname">
<span class="highlight"></span>
<span class="bar"></span>
<label>Crush Name</label>
</div>
<button id="calculate">Calculate</button>

<div class="footer">
<h2 id="result-message"></h2>
<p id="result-percentage"></p>

</div>


</div>
<script src="https://kit.fontawesome.com/4f3ce16e3e.js" crossorigin="anonymous"></script>
<script src="script.js"></script>

</body>

</html>
114 changes: 11 additions & 103 deletions Calculators/Love-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,15 @@
var name1 = document.getElementById("name1");
var name2 = document.getElementById("name2");
var calcBtn = document.querySelector("#btn");
var loveScore = Math.random() * 100;

var loveInfo = document.getElementById("loveInfo");
var reloadBtn = document.getElementById("reload");
loveScore = Math.floor(loveScore) + 1;

const body = document.querySelector("body");

function createHeart() {
const heart = document.createElement("div");
heart.className = "fas fa-heart";
heart.style.left = (Math.random() * 100) + "vw";
heart.style.animationDuration = (Math.random() * 3) + 2 + "s"
body.appendChild(heart);
window.onload = function() {
let button = document.getElementById("calculate");
button.addEventListener("click", calculateLove)
}

//capitalize input values
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function calculateLove() {
let yourName = document.getElementById("fname").value;
let crushName = document.getElementById("cname").value;

// Love Score Counter
function love() {
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
(async function () {
var i = 0;
while (i < loveScore) {
document.getElementById("score").innerHTML = i + "%";
await sleep(20);
i++;
}
})();
}

const hash = function (str, seed = 0) {
let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 =
Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 =
Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};

// Add eventlistener to button
calcBtn.addEventListener("click", function (e) {
if (
hash(name1.value.toUpperCase()) === 493572976860604 &&
hash(name2.value.toUpperCase()) === 8563725863411927
) {
loveScore = Math.random() * (100 - 90) + 90;
} else {
loveScore = Math.random() * 100; //delete this line if you want to keep the same value in the same session.
}
e.preventDefault();
if (name1.value == "" && name2.value == "") {
alert("You can't leave fields empty");
return;
}
else if (name1.value == "") {
alert("Please Enter Your Name");
if (yourName != "" && crushName != "") {
let percentage = Math.floor(Math.random() * 101);
document.getElementById("result-message").innerText = yourName + " and " + crushName + " 's chance of love: ";
document.getElementById("result-percentage").innerText = percentage.toString() + "%";
}
else if (name2.value == "") {
alert("Please Enter His/Her Name");
}
love();
if (loveScore > 90) {
setInterval(createHeart, 100);
setInterval(function name(params) {
var heartArr = document.querySelectorAll(".fa-heart")
if (heartArr.length > 200) {
heartArr[0].remove()
}
}, 100)
}
});

//if loveScore is greater than 90, then call the createHeart function


//function to reset the values
function reset() {
window.location.reload();
}

function validateName(inputId) {
let input = document.getElementById(inputId);
let value = input.value;
let regex = /^[A-Za-z ]+$/;

if (!regex.test(value)) {
alert("Please enter only characters in the name field.");
input.value = value.replace(/[^A-Za-z ]/g, ''); // Remove any non-alphabetic characters
}
}
}
Loading

0 comments on commit 25053f5

Please sign in to comment.