Advertisement
Guest User

Untitled

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