Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let wordNumValue = 0;
- let player2 = 0;
- let player1 = 0;
- let nameOfPlayer2 = '';
- let nameOfPlayer1 = '';
- for (let i = 0; i < input.length; i++) {
- if (input[i] !== 'Stop') {
- if (isNaN(input[i]) && input[i] !== 'Stop') {
- player2 = 0;
- nameOfPlayer2 = '';
- nameOfPlayer2 = input[i];
- for (let j = 0; j < input[i].length; j++) {
- wordNumValue = input[i].charCodeAt(j);
- if (wordNumValue === Number(input[i + j + 1])) {
- player2 += 10;
- } else {
- player2 += 2;
- }
- } // Inner loop
- }
- if (player2 > 0 && player1 === 0) {
- player1 = player2;
- nameOfPlayer1 = nameOfPlayer2;
- }
- } else {
- break;
- }
- } // Outer loop
- if (player1 > player2) {
- console.log(`The winner is ${nameOfPlayer1} with ${player1} points!`);
- } else if (player2 > player1) {
- console.log(`The winner is ${nameOfPlayer2} with ${player2} points!`);
- } else {
- console.log(`The winner is ${nameOfPlayer2} with ${player2} points!`);
- }
- // console.log(nameOfPlayer1, player1, nameOfPlayer2, player2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement