-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.js
84 lines (74 loc) · 2.64 KB
/
calc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function myFunction() {
var name=(document.getElementById("name").value).toLowerCase();
var pname=(document.getElementById("pname").value).toLowerCase();
if ((name.trim().length==0) || (pname.trim().length==""))
{
document.getElementById("alert").innerHTML = "Enter required fields"
return;
}
else{
var sname = (name.split(" ").join("")).split("");
var spname = (pname.split(" ").join("")).split("");
if (JSON.stringify(sname)==JSON.stringify(spname)){
document.getElementById("result").innerHTML ="Wow! Perfect relationship!";
return;
}
for (let i=0;i<sname.length;i++){
for(let j=0;j<spname.length;j++){
if (sname[i]==spname[j]){
sname.splice(i,1);
spname.splice(j,1);
i=i-1;
break;
}
}
}
let difference = [...sname,...spname];
console.log(difference,difference.length)
var flames = ["F","L","A","M","E","S"];
var start =0;
var i =0;
var j =0;
do{
if (j>flames.length-1){
j=(start + j-1) % (flames.length-1);
}
if (i==difference.length-1){
c=flames.splice(j,1);
i=0;
continue;
}
i++;
j++;
}while(flames.length!=1);
console.log(flames[0])
switch(flames[0]){
case "F":
document.getElementById("result").innerHTML ="Friendship!";
break;
case "L":
document.getElementById("result").innerHTML ="Love!";
break;
case "A":
document.getElementById("result").innerHTML ="Affection!";
break;
case "M":
document.getElementById("result").innerHTML ="Marriage!";
break;
case "E":
document.getElementById("result").innerHTML ="Enemy!";
break;
case "S":
document.getElementById("result").innerHTML ="Sister!";
break;
}
}
return;
}
function resetFun(){
document.getElementById("name").value="";
document.getElementById("pname").value="";
document.getElementById("name").focus();
document.getElementById("alert").innerHTML ="";
document.getElementById("result").innerHTML ="";
}