Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function examPreparation(input) {
- let gradesNumber = Number(input[0])
- let numberOfGrades = 0 //брой добри оценки
- let unsatisfactoryRating = 0 // брой незадоволителни оценки
- let sumGrades = 0 // сума оценки
- let taskCounter = 0
- let index = 1
- let nameTask = input[index]
- while (nameTask !== "Enough") {
- taskCounter++
- index++
- nameTask = input[index]
- let task = Number(input[index])
- if (task <= 4) {
- unsatisfactoryRating++
- sumGrades+=task
- } else {
- numberOfGrades++
- sumGrades += task
- }
- if (unsatisfactoryRating === gradesNumber) {
- console.log(`You need a break, ${unsatisfactoryRating} poor grades.`)
- break;
- } else {
- index++
- nameTask = input[index]
- }
- }
- let averageGrade = (sumGrades / taskCounter).toFixed(2)
- if (nameTask === "Enough") {
- console.log(`Average score: ${averageGrade}`)
- console.log(`Number of problems: ${taskCounter}`)
- console.log(`Last problem: ${input[index-2]}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement