Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nameGame(input) {
- let index = 0;
- let command = input[index];
- index++;
- let bestPoints = 0;
- let bestPlayer = "";
- while (command !== "Stop") {
- let playerPoints = 0;
- for (let i = 1; i <= command.length; i++){
- let number = Number(input[index]);
- index++;
- let letterValue = command.charCodeAt(i - 1);
- if (number === letterValue) {
- playerPoints += 10;
- } else {
- playerPoints += 2;
- }
- }
- if (playerPoints >= bestPoints) {
- bestPoints = playerPoints;
- bestPlayer = command;
- }
- command = input[index];
- index++;
- }
- console.log(`The winner is ${bestPlayer} with ${bestPoints} points!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment