Advertisement
Spocoman

Darts Tournament

Oct 6th, 2023
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cruiseGames(input) {
  2.     let startPoints = Number(input[0]);
  3.     let moves = 0;
  4.     let index = 1;
  5.  
  6.     while (startPoints > 0) {
  7.         let command = input[index++];
  8.         moves++;
  9.  
  10.         if (command == "bullseye") {
  11.             break;
  12.         }
  13.  
  14.         let points = Number(input[index++]);
  15.  
  16.         if (command == "double ring") {
  17.             points *= 2;
  18.         } else if (command == "triple ring") {
  19.             points *= 3;
  20.         }
  21.  
  22.         startPoints -= points;
  23.     }
  24.  
  25.     if (startPoints == 0) {
  26.         console.log(`Congratulations! You won the game in ${moves} moves!`);
  27.     } else if (startPoints < 0) {
  28.         console.log(`Sorry, you lost. Score difference: ${Math.abs(startPoints)}.`);
  29.     } else {
  30.         console.log(`Congratulations! You won the game with a bullseye in ${moves} moves!`);
  31.     }
  32.     return;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement