Advertisement
Guest User

04. Darts Tournament

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