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