Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cruiseGames(input) {
- let startPoints = Number(input[0]);
- let moves = 0;
- let index = 1;
- while (startPoints > 0) {
- let command = input[index++];
- moves++;
- if (command == "bullseye") {
- break;
- }
- let points = Number(input[index++]);
- if (command == "double ring") {
- points *= 2;
- } else if (command == "triple ring") {
- points *= 3;
- }
- startPoints -= points;
- }
- if (startPoints == 0) {
- console.log(`Congratulations! You won the game in ${moves} moves!`);
- } else if (startPoints < 0) {
- console.log(`Sorry, you lost. Score difference: ${Math.abs(startPoints)}.`);
- } else {
- console.log(`Congratulations! You won the game with a bullseye in ${moves} moves!`);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement