-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem-4.js
25 lines (20 loc) · 964 Bytes
/
problem-4.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
function calculateFinalScore(obj) {
if (typeof obj === 'object' &&
!Array.isArray(obj) &&
typeof obj.name === 'string' &&
typeof obj.testScore === 'number' &&
obj.testScore <= 50 &&
typeof obj.schoolGrade === 'number' &&
obj.schoolGrade <= 30 &&
typeof obj.isFFamily === 'boolean' &&
!isNaN(obj.schoolGrade) &&
!isNaN(obj.schoolGrade)
) {
const score = obj.isFFamily ? obj.testScore + obj.schoolGrade + 20 : obj.testScore + obj.schoolGrade;
return score >= 80 ? true : false;
} else return 'Invalid Input';
}
console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: true }));
console.log(calculateFinalScore({ name: "Rajib", testScore: 45, schoolGrade: 25, isFFamily: false }));
console.log(calculateFinalScore("hello"));
console.log(calculateFinalScore({ name: "Rajib", testScore: 15, schoolGrade: 25, isFFamily: true }));