-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
114 lines (98 loc) · 4.18 KB
/
app.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
const arithmetic = document.getElementById('arithmetic')
const arFirstTerm = document.getElementById('arFirstTerm')
const arSecondTerm = document.getElementById('arSecondTerm')
const arNumberOfTerm = document.getElementById('arNumberOfTerm')
const geometric = document.getElementById('geometric')
const geFirstTerm = document.getElementById('geFirstTerm')
const geSecondTerm = document.getElementById('geSecondTerm')
const geNumberOfTerm = document.getElementById('geNumberOfTerm')
const submitBtn = document.getElementById('submitBtn')
selectId.addEventListener('change', () =>{
const selectId = document.getElementById('selectId')
const selectIdValue = selectId.options[selectId.selectedIndex].value;
if(selectIdValue==='arithmetic'){
document.getElementById('first__section').style.display='block'
document.getElementById('second__section').style.display='none';
submitBtn.style.display='block';
submitBtn.style.margin='0 auto';
}
else if(selectIdValue==='geometric'){
document.getElementById('second__section').style.display='block';
document.getElementById('first__section').style.display='none';
submitBtn.style.display='block';
submitBtn.style.margin='0 auto';
}
else if (selectIdValue===''){
document.getElementById('first__section').style.display='none';
document.getElementById('second__section').style.display='none';
submitBtn.style.display='none';
}
});
submitBtn.addEventListener('click', (e)=>{
e.preventDefault();
const selectId = document.getElementById('selectId')
const selectIdValue = selectId.options[selectId.selectedIndex].value;
const arFirstTermValue = parseInt(arFirstTerm.value)
const arSecondTermValue = parseInt(arSecondTerm.value)
const arNumberOfTermValue = parseInt(arNumberOfTerm.value)
const geFirstTermValue = parseInt(geFirstTerm.value)
const geSecondTermValue = parseInt(geSecondTerm.value)
const geNumberOfTermValue = parseInt(geNumberOfTerm.value)
if(selectIdValue==='arithmetic'){
const d = arSecondTermValue - arFirstTermValue;
const sumation = (arNumberOfTermValue/2)*(2*arFirstTermValue+(arNumberOfTermValue-1)*d)
if(Number.isNaN(d) && Number.isNaN(sumation)){
swal({
title: "দয়া করে সঠিক সংখ্যা প্রবেশ করান",
text: '',
icon: "warning",
button:"ঠিক আছে"
});
}
else{
swal({
title: "ধারাটির" + " " + arNumberOfTermValue + " " +"টি পদের সমষ্টি " + sumation,
text: '',
icon: "success",
});
}
}
else if (selectIdValue==='geometric'){
const r = geSecondTermValue/geFirstTermValue;
if(Number.isNaN(r)){
swal({
title: "দয়া করে সঠিক সংখ্যা প্রবেশ করান",
text: '',
icon: "warning",
button:"ঠিক আছে"
});
}
else{
if(r>1){
sumation = (geFirstTermValue*((r**geNumberOfTermValue)-1))/(r-1);
swal({
title: "ধারাটির" + " " + geNumberOfTermValue + " " +"টি পদের সমষ্টি " + sumation,
text: '',
icon: "success",
});
}
else if (r<1){
sumation = (geFirstTermValue*(1-(r**geNumberOfTermValue)))/(1-r);
swal({
title: "ধারাটির" + " " + geNumberOfTermValue + " " +"টি পদের সমষ্টি " + sumation,
text: '',
icon: "success",
});
}
}
}
handleReset()
})
const handleReset = () => {
arFirstTerm.value =''
arSecondTerm.value =''
arNumberOfTerm.value=''
geFirstTerm.value =''
geSecondTerm.value =''
geNumberOfTerm.value=''
}