ErolKZ

Untitled

Jun 8th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5.  
  6. let totalPoints = 0;
  7.  
  8. let pointRed = 0;
  9.  
  10. let pointOrange = 0;
  11.  
  12. let pointYellow = 0;
  13.  
  14. let pointWhite = 0;
  15.  
  16. let otherColor = 0;
  17.  
  18. let countBlack = 0;
  19.  
  20.  
  21. for (let i = 1; i < input.length; i++) {
  22.  
  23.  
  24. if (input[i] === 'red') {
  25.  
  26. totalPoints = totalPoints + 5;
  27.  
  28. pointRed = pointRed + 1;
  29.  
  30. } else if (input[i] === 'orange') {
  31.  
  32. totalPoints = totalPoints + 10;
  33.  
  34. pointOrange = pointOrange + 1;
  35.  
  36. } else if (input[i] === 'yellow') {
  37.  
  38. totalPoints = totalPoints + 15;
  39.  
  40. pointYellow = pointYellow + 1;
  41.  
  42. } else if (input[i] === 'white') {
  43.  
  44. totalPoints = totalPoints + 20;
  45.  
  46. pointWhite = pointWhite + 1;
  47.  
  48. } else if (input[i] === 'black') {
  49.  
  50. totalPoints = Math.floor(totalPoints / 2);
  51.  
  52. countBlack = countBlack + 1;
  53.  
  54.  
  55.  
  56. } else {
  57.  
  58. otherColor = otherColor + 1;
  59.  
  60. }
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69. console.log(`Total points: ${totalPoints}`);
  70. console.log(`Points from red balls: ${pointRed}`);
  71. console.log(`Points from orange balls: ${pointOrange}`);
  72. console.log(`Points from yellow balls: ${pointYellow}`);
  73. console.log(`Points from white balls: ${pointWhite}`);
  74. console.log(`Other colors picked: ${otherColor}`);
  75. console.log(`Divides from black balls: ${countBlack}`);
  76.  
  77.  
  78.  
  79.  
  80.  
  81. }
  82.  
  83.  
  84. solve(['3', 'white', 'black', 'pink']);
  85.  
Advertisement
Add Comment
Please, Sign In to add comment