Advertisement
Spocoman

Balls

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