Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let score = Number(input.shift());
- let counter = 0;
- while (score > 0) {
- let section = input.shift();
- let incomeScore = Number(input.shift());
- if (section == "bullseye") {
- counter++;
- break;
- }
- switch (section) {
- case "number section": score -= incomeScore; break;
- case "double ring": score -= incomeScore * 2; break;
- case "triple ring": score -= incomeScore * 3; break;
- }
- counter++;
- }
- if (score === 0) {
- console.log(`Congratulations! You won the game in ${counter} moves!`)
- } else if (score > 0) {
- console.log(`Congratulations! You won the game with a bullseye in ${counter} moves!`);
- } else {
- console.log(`Sorry, you lost. Score difference: ${Math.abs(score)}.`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement