Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
// Write all your code here
// Replace the contents of this file with your own code
console.log('Hello, world!');
let options = ["Rock","Paper","Scissors"]
function computerPlay() {
return options[Math.floor(Math.random()*options.length)]
}

function playRound (playerSelection, computerSelection) {

if (playerSelection =="Rock" && computerSelection == "Scissors") {
return ("You Won! Rock beats Scissors")
} else if (playerSelection =="Rock" && computerSelection == "Paper") {
return ("You Lose! Paper beats Rock")
} else if (playerSelection =="Rock" && computerSelection == "Rock") {
return ("Play again")
} else if (playerSelection =="Paper" && computerSelection == "Rock") {
return ("You Won! Paper beats Rock")
} else if (playerSelection =="Paper" && computerSelection == "Scissors") {
return ("You Lose! Scissors beats Paper")
} else if (playerSelection =="Paper" && computerSelection == "Paper") {
return ("Play again")
} else if (playerSelection =="Scissors" && computerSelection == "Scissors") {
return ("Play again")
} else if (playerSelection =="Scissors" && computerSelection == "Paper") {
return ( "You Won! Scissors beats Paper")
} else if (playerSelection =="Scissors" && computerSelection == "Rock") {
return ("You Lose! Rock beats Scissors")
} else {
return ( "Something went terribly wrong, play again!!!")
}
}


function titleCase(str) {
return str.replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}

function game() {
for (i=0;i<5;i++){
let playerSelection = titleCase(prompt("Please enter your selection"))
let computerSelection = computerPlay()
console.log (playRound (playerSelection, computerSelection))
}
}
game()