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