Halllp. Cant seem to do the part 2 of the Rock Paper Scissors challenge


#1

I can make the game play, tell you if you win, and assign a valio like 1 0 but after i run it again those numbers reset here is my code, hopefully ill get some feedback.

//Computer play******************************

function computerPlay(){
var cPlay;
var thrw = Math.floor((Math.random() * 3) + 1);
if (thrw === 1){
cPlay = ‘Rock’;
} else if (thrw === 2){
cPlay = ‘Paper’;
} else {
cPlay = ‘Scissors’;
} return cPlay
}

//User Play **********************************************
function userPlay( ){
var thrw = prompt(‘Choose one. Rock Paper or Scissors’).toLowerCase();
if (thrw === ‘rock’){
uPlay = ‘Rock’;
} else if (thrw === ‘paper’){
uPlay = ‘Paper’;
} else if(thrw === ‘scissors’) {
uPlay = ‘Scissors’;
} else {
uPlay = 4;
}
return uPlay
}

const userSelection = userPlay();
const computerSelection = computerPlay();

var userScore = 0;
var compScore = 0;

function game () {

    function playRound(uThrw, cThrw) {       
                           
        if (uThrw === 'Rock' && cThrw === 'Rock' ){
           return 'Tie';
        }else if (uThrw === 'Rock'  && cThrw === 'Paper'){
           compScore++;
           return 'Lose';
        }else if (uThrw === 'Rock' && cThrw === 'Scissors'){
         		userScore++;
            return 'Win';
        }else if (uThrw === 'Paper' && cThrw === 'Rock'){
         		userScore++;
            return 'Win';
        }else if (uThrw === 'Paper'  && cThrw === 'Paper'){
            return 'Tie';
        }else if (uThrw === 'Paper' && cThrw === 'Scissors'){
           	compScore++;
            return 'Lose';
        }else if (uThrw === 'Scissors' && cThrw === 'Rock'){
          	compScore++;
            return ' Lose';
        }else if (uThrw === 'Scissors' && cThrw === 'Paper'){
          	compScore++;
            return 'Win';
        }else if (uThrw === 'Scissors' && cThrw === 'Scissors'){
            return 'Tie';
        }else {
            return 'Invalid Input'
        }
         } 
    console.log(playRound(userSelection, computerSelection));
    console.log(compScore, userScore);


}

game();


#2

Hi @jofer86

Each time you run the script everything gets reset as the code is completely parsed fresh.

To keep track you’d need to run the game in a loop or something. If you don’t know how to do that yet then don’t worry. Just carry on through the resources.