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