-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
149 lines (145 loc) · 6.63 KB
/
script.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// JavaScript code
//Search Function
function search_animal() {
let input = document.getElementById('searchbar').value
input = input.toLowerCase();
let x = document.getElementsByClassName('subjects');
for (i = 0; i < x.length; i++) {
if (!x[i].innerHTML.toLowerCase().includes(input)) {
x[i].style.display = "none";
}
else {
x[i].style.display = "list-item";
}
}
}
//Square Number Calculate
function squarecalc(){
var squaresolveanswer = Number(document.getElementById("squaresolve").value * Number(document.getElementById("squaresolve").value));
document.getElementById("squareanswer").innerText = comma(squaresolveanswer);
}
//Cube Number Calculate
function cubecalc(){
var cubesolveanswer = Number(document.getElementById("cubesolve").value * document.getElementById("cubesolve").value * document.getElementById("cubesolve").value);
document.getElementById("cubeanswer").innerText = comma(cubesolveanswer);
}
//Triangle Number Calculate
function trianglecalc(){
var trianglesolveanswer = document.getElementById("trianglesolve").value;
var trianglenumber = trianglesolveanswer;
var trianglenumberadd1 = trianglenumber;
trianglenumberadd1 ++;
var trianglenumber2 = trianglenumber * trianglenumberadd1;
trianglenumber = trianglenumber2 /2;
document.getElementById("triangleanswer").innerText = comma(trianglenumber);
}
//Tetrahedral Number Calculate
function tetrahedralcalc(){
var tetrahedralsolveanswer = Number(document.getElementById("tetrahedralsolve").value);
var t = tetrahedralsolveanswer;
var tetrahedraladd1 = t+=1;
var tetrahedraladd2 = tetrahedraladd1 +=1;
tetrahedraladd1 --;
var tetrahedraladd3 = tetrahedraladd2 +=1;
tetrahedraladd2 --;
var tetrahedral = tetrahedraladd1 * tetrahedraladd2 * tetrahedraladd3;
var tetrahedrald6 = tetrahedral /6;
document.getElementById("tetrahedralanswer").innerText = comma(tetrahedrald6);
}
//Fibonaci Number Calculate
function fibo( num){
var n1 = 0;
var n2 = 1;
var temp;
var i = 0;
for (i = 0; i < num; i++){
temp = n1 + n2;
n1 = n2;
n2 = temp;
}
return n2;
}
function fibonaccicalc(){
var f1 = Number(document.getElementById("fibonaccisolve").value);
document.getElementById("fibonaccianswer").innerText = comma(fibo(f1));
}
//Arithmetic Progression
function arithmeticcalc(){
const a = Number(document.getElementById("arithmeticsolve1").value), b = Number(document.getElementById("arithmeticsolve2").value);
const N = Number(document.getElementById("arithmeticsolvef").value);
const findNthTerm = (first, second, num) => {
const diff = second - first;
const fact = (num - 1) * diff;
const term = first + fact;
return term;
};
document.getElementById("arithmeticanswer").innerText = comma(findNthTerm(a, b, N));
}
//Prime or Composite?
function primecalc(){
var isPrime = "true";
var corp = Number(document.getElementById("primesolve").value); // corp means composite or prime, not corporation
if (corp <= 0){
document.getElementById("primeanswer").innerText = "Can't calculate with 0 or a negative number."
}
if (corp === 1) {
document.getElementById("primeanswer").innerText = "1 is neither prime nor composite number.";
}
else if (corp > 1) {
for (let z = 2; z < corp; z++) {
if (corp % z == 0) {
isPrime = "false";
break;
}
}
if (isPrime == "true") {
document.getElementById("primeanswer").innerText = comma((corp)) + (" is a prime number (not a composite number).");
} else {
document.getElementById("primeanswer").innerText = comma((corp)) + (" is a composite number (not a prime number).");
}
}
}
//Circle Calculate
function circlecalc(){
var CircumferenceDiameter = document.getElementById("CircumferenceDiameterSolve").value;
var CircumferenceDiameter2 = CircumferenceDiameter * 2 * Math.PI;
var CircumferenceDiameter3 = (CircumferenceDiameter * CircumferenceDiameter);
CircumferenceDiameter3 = CircumferenceDiameter3 * Math.PI;
CircumferenceDiameter2 = CircumferenceDiameter2;
document.getElementById("circleroundthing").innerText = ("All values are rounded to 5 decimal points.");
document.getElementById("circleanswer").innerText = ("Circumferenc = ") + Math.round((CircumferenceDiameter2 + Number.EPSILON) * 100000) / 100000;
document.getElementById("circlediameteranswer").innerText = ("Diameter = ") + Math.round(((CircumferenceDiameter * 2) + Number.EPSILON) * 100000) / 100000;
document.getElementById("circleareaanswer").innerText = ("Area = ") + Math.round((CircumferenceDiameter3 + Number.EPSILON) * 100000) / 100000;
};
//circles
function circlecalcradius(){
var diameter = document.getElementById("RadiusSolve").value;
var radius = diameter * 2;
document.getElementById("circleroundthing2").innerText = ("All values are rounded to 5 decimal points.");
document.getElementById("circleradius").innerText = ("Radius = ") + Math.round((radius + Number.EPSILON) * 100000) / 100000;
};
//random number generator
function choosenumber(){
var secondrandomnumber = Number(document.getElementById("lastnumber").value);
var randomnumberfinal = Math.floor(Math.random() * secondrandomnumber) + 1;
if (randomnumberfinal == 69) {
randomnumberfinal = ("69, lol");
}
document.getElementById("randomanswer").innerText = ("Your random number (inclusive of 1 and ") + secondrandomnumber + (") is ") + randomnumberfinal;
};
//loan calculator
function calculateloan() {
var amount = Number(document.getElementById("loanamount").value)
var rate = Number(document.getElementById("interestrate").value)
var months = Number(document.getElementById("numberofmonths").value)
var interest = (amount * (rate * 0.01)) / months;
var totalamount = ((amount / months) + interest).toFixed(2);
var totalamountwithoutinterest = ((amount / months)).toFixed(2);
document.getElementById("interest").innerText = ("Interest is $") + interest;
document.getElementById("monthlypayment").innerText = ("Monthly payment (2 d.p., and with interest) is $") + totalamount;
document.getElementById("monthlypaymentwithoutinterest").innerText = ("Monthly payment (2 d.p. and without interest) is $") + totalamountwithoutinterest;
};
//comma
function comma(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}