Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Rock-Paper-Scissors

console.log("Rock, Paper, Scissors");

//Validate choice, make sure it is correct 

const readline = require("readline").createInterface({ input: process.stdin, output: process.stdout });

//call user response

readline.question("Let's Play?\n", tryAgainResponse);

readline.question("Try again? Y/N\n", tryAgainResponse); function tryAgainResponse(response) {

if (response.toLowerCase() === "y"){
    readline.question("Choose Rock, Paper, or Scissors??\n", handleUserResponse);
}
else if (response.toLowerCase() ==="n"){
    readline.close();
}
else {
    console.log("Invalid try again")
}    

}

//Validate choice, make sure it is correct //function to handleUserResponse

function handleUserResponse(response) {

let choices = ["rock", "paper", "scissors"]; let randomNum = choices[Math.floor(Math.random() * 3)]; console.log(randomNum);

//Random selection - Rock, Paper, Scissors //Compare choices //Who won?

if (response.toLowerCase() === randomNum){ console.log("Tie!"); } else if (response.toLowerCase() === 'paper' && randomNum === 'rock'){ console.log("You win! :)"); } else if (response.toLowerCase() === 'rock' && randomNum === 'scissors'){ console.log("You win! :)"); } else if (response.toLowerCase() === 'scissors' && randomNum === 'rock'){ console.log("You lose! :("); } else if (response.toLowerCase() === 'rock' && randomNum === 'paper'){ console.log("You lose! :("); } else if (response.toLowerCase() === 'paper' && randomNum === 'scissors'){ console.log("You lose! :("); } else if (response.toLowerCase() === 'scissors' && randomNum === 'paper'){ console.log("You win! :)"); } else{ console.log("Invalid, try again!!"); }

//console.log(response);
readline.close();

};

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages