Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function balls(input) {
- let numberOfBalls = Number(input[0]);
- let index = 1;
- let color = input[index];
- let points = 0;
- let redBallsCounter = 0;
- let orangeBallsCounter = 0;
- let yellowBallsCounter = 0;
- let whiteBallsCounter = 0;
- let blackBallsCounter = 0;
- let otherColorBallsCounter = 0;
- for (let i = 1; i <= numberOfBalls; i++) {
- if (color === "red") {
- points += 5;
- redBallsCounter++;
- } else if (color === "orange") {
- points += 10;
- orangeBallsCounter++;
- } else if (color === "yellow") {
- points += 15;
- yellowBallsCounter++;
- } else if (color === "white") {
- points += 20;
- whiteBallsCounter++;
- } else if (color === "black") {
- points = Math.floor(points / 2);
- blackBallsCounter++;
- } else {
- otherColorBallsCounter++;
- }
- index++;
- color = input[index];
- }
- console.log(`Total points: ${points}`);
- console.log(`Red balls: ${redBallsCounter}`);
- console.log(`Orange balls: ${orangeBallsCounter}`);
- console.log(`Yellow balls: ${yellowBallsCounter}`);
- console.log(`White balls: ${whiteBallsCounter}`);
- console.log(`Other colors picked: ${otherColorBallsCounter}`);
- console.log(`Divides from black balls: ${blackBallsCounter}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment