TZinovieva

Balls

Jun 13th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function balls(input) {
  2.         let numberOfBalls = Number(input[0]);
  3.         let index = 1;
  4.         let color = input[index];
  5.    
  6.         let points = 0;
  7.         let redBallsCounter = 0;
  8.         let orangeBallsCounter = 0;
  9.         let yellowBallsCounter = 0;
  10.         let whiteBallsCounter = 0;
  11.         let blackBallsCounter = 0;
  12.         let otherColorBallsCounter = 0;
  13.    
  14.         for (let i = 1; i <= numberOfBalls; i++) {
  15.            
  16.             if (color === "red") {
  17.                 points += 5;
  18.                 redBallsCounter++;
  19.             } else if (color === "orange") {
  20.                 points += 10;
  21.                 orangeBallsCounter++;
  22.             } else if (color === "yellow") {
  23.                 points += 15;
  24.                 yellowBallsCounter++;
  25.             } else if (color === "white") {
  26.                 points += 20;
  27.                 whiteBallsCounter++;
  28.             } else if (color === "black") {
  29.                 points = Math.floor(points / 2);
  30.                 blackBallsCounter++;
  31.             } else {
  32.                 otherColorBallsCounter++;
  33.             }
  34.             index++;
  35.             color = input[index];
  36.         }
  37.     console.log(`Total points: ${points}`);
  38.     console.log(`Red balls: ${redBallsCounter}`);
  39.     console.log(`Orange balls: ${orangeBallsCounter}`);
  40.     console.log(`Yellow balls: ${yellowBallsCounter}`);
  41.     console.log(`White balls: ${whiteBallsCounter}`);
  42.     console.log(`Other colors picked: ${otherColorBallsCounter}`);
  43.     console.log(`Divides from black balls: ${blackBallsCounter}`);
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment