-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrata2.js
More file actions
46 lines (44 loc) · 1 KB
/
Copy pathrata2.js
File metadata and controls
46 lines (44 loc) · 1 KB
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
const nilai = [80,90,89,69]
const [matematika, bahasaIndonesia, bahasaInggris, ipa] = nilai;
let ave
let total = 0
let j = nilai.length
let i = 0
while(i<j){
if(nilai[i]!==null && nilai[i]!==undefined){
if(typeof nilai[i]=="number"){
if(nilai[i]<=100 && nilai[i]>=0){
total+= nilai[i]
i++
}else{
console.log("Nilai harus diantara 0-100")
total = null
i = j
}
}else{
console.log("Nilai harus berupa angka")
total = null
i = j
}
}else{
console.log("Nilai tidak boleh kosong!")
total = null
i = j
}
}
if(total){
ave = total/j
if(ave>=90){
grade = "A"
}else if(ave>=80){
grade = "B"
}else if(ave>=70){
grade = "C"
}else if(ave>=60){
grade = "D"
}else{
grade = "E"
}
console.log(`Nilai Rata-Rata : ${ave}`)
console.log(`Grade : ${grade}`)
}