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