Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TODO
- function darts(input) {
- let index = 0;
- let player = input[index++];
- let points = 301;
- let successfulShots = 0;
- let unsuccessfulShots = 0;
- let command = input[index++];
- while((command !== 'Retire') && points !== 0) {
- let shot = Number(input[index++]);
- if(command === 'Double') {
- shot *= 2;
- } else if(command === 'Triple') {
- shot *= 3;
- }
- if(points >= shot) {
- points -= shot;
- successfulShots++;
- } else {
- unsuccessfulShots++;
- }
- command = input[index++];
- }
- if(points === 0) {
- console.log(`${player} won the leg with ${successfulShots} shots.`);
- } else if(command === 'Retire') {
- console.log(`${player} retired after ${unsuccessfulShots} unsuccessful shots.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement