-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSYTYCD-TypeScript.ts
More file actions
33 lines (29 loc) · 939 Bytes
/
SYTYCD-TypeScript.ts
File metadata and controls
33 lines (29 loc) · 939 Bytes
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
// A small program that checks student grades and gives feedback
function calculateAverage(grades: number[]): number {
let total = 0
for (let i = 0; i <= grades.length; i++) {
total += grades[i]
}
return total / grades.length
}
function giveFeedback(name: string, average: number) {
if (average = 100) {
console.log(name + " is a genius!")
} else if (average > 90) {
console.log(name + " did excellent work.")
} else if (average > 75 && average < 90) {
console.log(name + " did well.")
} else {
console.log(name + " needs to improve.")
}
}
const students = [
{ name: "Ali", grades: [100, 95, 90] },
{ name: "Sara", grades: [70, 60, 50] },
{ name: "Omar", grades: [85, 80, "75"] },
{ name: "Lina", grades: [null, 100, 90] }
]
for (let student of students) {
const avg = calculateAverage(student.grade)
giveFeedback(student.name, avg)
}