-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (53 loc) · 2.41 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
// This function clear all the values
function clearScreen() {
document.getElementById("result").value = "";
}
// This function display values
function display(value) {
document.getElementById("result").value += value;
}
function checkValue(sender) {
let min = sender.min;
let max = sender.max;
let value = parseInt(sender.value);
if (value>max) {
sender.value = max;
} else if (value<min) {
sender.value = max;
}
}
// This function evaluates the expression and returns result
function calculate() {
var amount = document.getElementById("amount").value;
var percentageJam = document.getElementById("percentageJam").value;
var percentageCustard = document.getElementById("percentageCustard").value;
var percentageNutella = document.getElementById("percentageNutella").value;
var description = "";
if ((parseInt(percentageCustard) + parseInt(percentageJam) + parseInt(percentageNutella)) > 100 || (parseInt(percentageCustard) + parseInt(percentageJam) + parseInt(percentageNutella)) < 100)
{
description = "The sum of the percentages should not be lower or higher than 100.";
document.getElementById("result").value = description;
return;
}
if ((amount < 0) || (percentageJam > 100 || percentageJam < 0 ) || (percentageCustard > 100 || percentageCustard < 0 ) || (percentageNutella > 100 || percentageNutella < 0 ))
{
description = "Invalid inputs."
document.getElementById("result").value = description;
return;
}
var resultJam = (amount / 100) * percentageJam;
var resultCustard = (amount / 100) * percentageCustard;
var resultNutella = (amount / 100) * percentageNutella;
var boxesJam = resultJam / 20;
var boxesCustard = resultCustard / 20;
var boxesNutella = resultNutella / 20;
description = `${resultJam} Jam Donuts (${boxesJam} boxes of jam) \n ${resultCustard} Custard Donuts (${boxesCustard} boxes of custard) \n ${resultNutella} Nutella Donuts (${boxesNutella} boxes of nutella)`
Swal.fire(
'Done!',
description,
'success'
)
document.getElementById("result").value = description;
}