Spocoman

Name Game

Feb 15th, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nameGame(input) {
  2.     let name = input.shift();
  3.     let winner = "";
  4.     let points = 0;
  5.  
  6.     while (name !== "Stop") {
  7.         let sum = 0;
  8.         for (let i = 0; i < name.length; i++) {
  9.             let num = Number(input.shift());
  10.  
  11.             if (num === name[i].charCodeAt(0)) {
  12.                 sum += 10;
  13.             } else {
  14.                 sum += 2;
  15.             }
  16.         }
  17.  
  18.         if (sum >= points) {
  19.             winner = name;
  20.             points = sum;
  21.         }
  22.  
  23.         name = input.shift();
  24.     }
  25.     console.log(`The winner is ${winner} with ${points} points!`);
  26. }
  27.  
Add Comment
Please, Sign In to add comment