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