Advertisement
bebo231312312321

Untitled

Feb 4th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function examPreparation(input) {
  2.     let gradesNumber = Number(input[0])
  3.     let numberOfGrades = 0 //брой добри оценки
  4.     let unsatisfactoryRating = 0 // брой незадоволителни оценки
  5.     let sumGrades = 0 // сума оценки
  6.     let taskCounter = 0
  7.    
  8.     let index = 1
  9.     let nameTask = input[index]
  10.  
  11.  
  12.     while (nameTask !== "Enough") {
  13.  
  14.         taskCounter++
  15.         index++
  16.         nameTask = input[index]
  17.  
  18.         let task = Number(input[index])
  19.         if (task <= 4) {
  20.             unsatisfactoryRating++
  21.             sumGrades+=task
  22.  
  23.         } else {
  24.             numberOfGrades++
  25.             sumGrades += task
  26.         }
  27.         if (unsatisfactoryRating === gradesNumber) {
  28.             console.log(`You need a break, ${unsatisfactoryRating} poor grades.`)
  29.             break;
  30.         } else {
  31.            
  32.             index++
  33.             nameTask = input[index]
  34.            
  35.         }
  36.        
  37.     }
  38.     let averageGrade = (sumGrades / taskCounter).toFixed(2)
  39.     if (nameTask === "Enough") {
  40.         console.log(`Average score: ${averageGrade}`)
  41.         console.log(`Number of problems: ${taskCounter}`)
  42.         console.log(`Last problem: ${input[index-2]}`)
  43.  
  44.     }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement