forked from SHOBUZ-ALI/grade-calculator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrade_calculator.js
66 lines (53 loc) · 1.81 KB
/
grade_calculator.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
const inputGradeMarks=document.getElementById('inputGrade');
const marksCalculate=document.getElementById('calculator');
const marksReset=document.getElementById('reset');
const errorMessageShow=document.getElementById('errorMessage');
const showResult=document.getElementById('result');
let error_class='border-red-500';
function resetErrorStyles(){
inputGradeMarks.classList.remove(error_class);
errorMessageShow.classList.add('hidden');
}
function isValidInput(){
resetErrorStyles();
if(!isValidInput.value){
inputGradeMarks.classList.add(error_class);
errorMessageShow.classList.remove('hidden');
errorMessageShow.textContent="plz enter a valid number";
return false;
}
if(inputGradeMarks.value<0 || inputGradeMarks.value>100){
inputGradeMarks.classList.add(error_class);
errorMessageShow.classList.remove('hiden');
errorMessageShow.textContent="plz enter number that is above 0 but less than 101";
return false;
}
return true;
}
marksCalculate.addEventListener("click", function(){
if(!isValidInput()){
return;
}
let score=parseFloat(inputGradeMarks.value);
if(score>0 && score<32){
showResult.textContent="F";
}else if(score>=33 && score<39){
showResult.textContent="D";
}else if(score>=40 && score<49){
showResult.textContent="C";
}else if(score>=50 && score<59){
showResult.textContent="B";
}else if(score>=60 && score<69){
showResult.textContent="A-";
}else if(score>=70 && score<79){
showResult.textContent="A";
}else if(score>=80 && score<100){
showResult.textContent="A+";
}
});
marksReset.addEventListener('click',function(){
inputGradeMarks.value='';
showResult.textContent='';
errorMessageShow.textContent='';
resetErrorStyles();
});