Advertisement
Grossos

06. Easter Competition

Jun 28th, 2023
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterCompetition(input) {
  2.     let index = 0;
  3.     let easterBread = Number(input[index]);
  4.     index++
  5.     let command = input[index];
  6.     index++
  7.     let points = 0
  8.     let localPoints = 0;
  9.     let counter = 0;
  10.     let bestChef = '';
  11.     let bestScore = 0;
  12.  
  13.     for (let i = 0; i < easterBread; i++) {
  14.         counter++
  15.         points = 0;
  16.         let chef = command
  17.         command = input[index];
  18.         index++;
  19.  
  20.  
  21.         while (command !== 'Stop') {
  22.             localPoints = Number(command);
  23.             points += localPoints
  24.  
  25.             command = input[index];
  26.             index++
  27.         }
  28.         // След получаване на командата "Stop" се печата един ред:
  29.         // "{името на пекаря} has {общият брой получени точки} points."
  30.         console.log(`${chef} has ${points} points.`);
  31.  
  32.         // if (points >= bestScore) {
  33.         //Ако след командата "Stop", пекарят е с най-много точки до момента, да се отпечата допълнителен ред:
  34.         //"{името на пекаря} is the new number 1!"
  35.         if (points > bestScore) {
  36.             bestScore = points;
  37.             bestChef = chef
  38.             console.log(`${chef} is the new number 1!`);
  39.         }
  40.         // if (counter === 1) {
  41.         //     console.log(`${chef} has ${points} points.`);
  42.         // } else {
  43.         //     console.log(`${chef} has ${points} points.`)
  44.         // }
  45.         command = input[index];
  46.         index++;
  47.     }
  48.  
  49.     console.log(`${bestChef} won competition with ${bestScore} points!`);
  50. }
  51. easterCompetition(["3",
  52. "Chef Manchev",
  53. "10",
  54. "10",
  55. "10",
  56. "10",
  57. "Stop",
  58. "Natalie",
  59. "8",
  60. "2",
  61. "9",
  62. "Stop",
  63. "George",
  64. "9",
  65. "2",
  66. "4",
  67. "2",
  68. "Stop"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement