-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
129 lines (104 loc) · 4.62 KB
/
index.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
{
const duzina = document.querySelector(".duzina");
const sirina = document.querySelector(".sirina");
const debljina = document.querySelector(".debljina");
const klasa = document.querySelector(".klasa");
const premaz = document.querySelector(".premaz")
const izracunaj = document.querySelector(".izracunaj")
const cena = document.querySelector(".cena")
// funkcija pokupi vrednosti iz inputa i upise u objekat
const getInputValues = () => {
return {
x: duzina.value,
y: sirina.value,
z: debljina.value,
klasa: klasa.value,
premaz: premaz.value
}
}
// funkcija prima debljinu i klasu iz inputa i na osnovu odabranih parametara upisuje cene ploce u objekat
const getType = (a, b) => {
const prices = {
basePrice:0, //osnovna cena za ploce do 2m
// lowerPrice: 0, // cena za plocu duzine manje od 2m
// higherPrice: 0 // cena za plocu duzine vece od 2m
}
switch (a + "|" + b) {
case "20|AB":
prices.basePrice= 80;
// prices.lowerPrice = 80;
// prices.higherPrice = 96;
break;
case "20|BC":
prices.basePrice= 54;
// prices.lowerPrice = 54;
// prices.higherPrice = 64.8;
break;
case "40|AB":
prices.basePrice= 160;
// prices.lowerPrice = 160;
// prices.higherPrice = 192;
break;
case "40|BC":
prices.basePrice= 108;
// prices.lowerPrice = 108;
// prices.higherPrice = 129.6;
break;
default:
console.log("error")
break;
}
return prices
}
//funkcija uzima potrebne parametre izracunava cenu na osnovu duzine ploce i upisuje u h2
const priceCalculation = () => {
const { x, y, z, klasa, premaz } = getInputValues()
// const { lowerPrice, higherPrice } = getType(z, klasa)
const { basePrice } = getType(z, klasa)
let length = x / 100
let width = y / 100
let height = parseInt(z) / 1000
let surfaceArea = length * width
let sideSurface = height * (length + width) // ukupna povrsina bocnih strana
const calcForDimensions = (l, price) => {
return (price + l*price)
}
// length > 2 || width > 2 ?
// cena.innerHTML = (Math.floor((surfaceArea * (higherPrice + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
// :
// cena.innerHTML = (Math.floor((surfaceArea * (lowerPrice + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
if( length < 2 || width < 2 ){
cena.innerHTML = (Math.floor((surfaceArea * (basePrice + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
}else if((length >= 2 || width >= 2) && (length < 3 && width < 3) ){
cena.innerHTML = (Math.floor((surfaceArea * (calcForDimensions(0.2 , basePrice) + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
}else if((length >= 3 || width >= 3) && (length < 4 && width < 4 )) {
cena.innerHTML = (Math.floor((surfaceArea * (calcForDimensions(0.3 , basePrice) + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
}else if ((length >= 4 || width >= 4) && (length < 5 && width < 5 )){
cena.innerHTML = (Math.floor((surfaceArea * (calcForDimensions(0.4 , basePrice) + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
}else if ((length === 5 || width === 5)&&(length < 5 || width < 5)){
cena.innerHTML = (Math.floor((surfaceArea * (calcForDimensions(0.5 , basePrice) + parseInt(premaz)) + sideSurface * parseInt(premaz)) * 100) / 100) + " evra"
}else{
console.log("hello")
cena.innerHTML="max 5m"
}
}
izracunaj.addEventListener("click", () => {
const { x, y } = getInputValues()
if (!x && !y) {
duzina.classList.add("invalid");
sirina.classList.add("invalid");
return
}
else if (!x) {
duzina.classList.add("invalid");
}
else if (!y) {
sirina.classList.add("invalid");
}
else {
duzina.classList.remove("invalid");
sirina.classList.remove("invalid");
priceCalculation()
}
})
}