ErolKZ

Untitled

Jul 22nd, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let index = 0;
  6.  
  7. let player1 = 0;
  8.  
  9. let player2 = 0;
  10.  
  11. let namePlayer1 = '';
  12.  
  13. let currentName = '';
  14.  
  15.  
  16.  
  17. while (input[index] !== 'Stop') {
  18.  
  19.  
  20. if (index > 0) {
  21.  
  22. currentName = input[index];
  23.  
  24. index++;
  25.  
  26. } else {
  27.  
  28. currentName = input[index];
  29.  
  30. index++;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. for (let i = 0; i < currentName.length; i++) {
  37.  
  38. let currentNumber = Number(input[index]);
  39.  
  40. if (currentName.charCodeAt(i) === currentNumber) {
  41.  
  42. player2 += 10;
  43.  
  44. } else {
  45.  
  46. player2 += 2;
  47.  
  48. }
  49.  
  50.  
  51. index++;
  52. }
  53.  
  54.  
  55. if (input[index] !== 'Stop') {
  56.  
  57. namePlayer1 = currentName;
  58.  
  59. player1 = player2;
  60.  
  61. player2 = 0;
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. if (player1 > player2) {
  73.  
  74. console.log(`The winner is ${namePlayer1} with ${player1} points!`);
  75.  
  76. } else if (player2 > player1) {
  77.  
  78. console.log(`The winner is ${currentName} with ${player2} points!`);
  79.  
  80.  
  81. } else {
  82.  
  83. console.log(`The winner is ${currentName} with ${player2} points!`);
  84.  
  85. }
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment