Write getCompChoice function and successfully test it and the prompt
This commit is contained in:
parent
a5537d23d2
commit
982c92bbf2
1 changed files with 16 additions and 8 deletions
24
script.js
24
script.js
|
|
@ -1,8 +1,13 @@
|
||||||
function getComputerChoice(){
|
function getComputerChoice(){
|
||||||
// get random number between 1 and 3
|
let compAnswer = Math.floor(Math.random() * 3) + 1;
|
||||||
// if 1, return "rock"
|
|
||||||
// if 2, return "paper"
|
if (compAnswer === 1) {
|
||||||
// if 3, return "scissors"
|
return "rock";
|
||||||
|
} else if (compAnswer === 2) {
|
||||||
|
return "paper";
|
||||||
|
} else {
|
||||||
|
return "scissors"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playRound(playerSelection, computerSelection){
|
function playRound(playerSelection, computerSelection){
|
||||||
|
|
@ -17,9 +22,11 @@ function playRound(playerSelection, computerSelection){
|
||||||
//else if p === "paper"
|
//else if p === "paper"
|
||||||
//if c === "scissors" player loses
|
//if c === "scissors" player loses
|
||||||
//if c === "rock" player wins
|
//if c === "rock" player wins
|
||||||
//else (p === scissors)
|
//else if p === scissors
|
||||||
//if c === "rock" player loses
|
//if c === "rock" player loses
|
||||||
//if c === "paper" player wins
|
//if c === "paper" player wins
|
||||||
|
// else
|
||||||
|
//Not a valid entry
|
||||||
}
|
}
|
||||||
|
|
||||||
function game(playerSelection, computerSelection) {
|
function game(playerSelection, computerSelection) {
|
||||||
|
|
@ -32,7 +39,8 @@ function game(playerSelection, computerSelection) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// const ps = prompt("Rock, Paper or Scissors?")
|
const ps = prompt("Rock, Paper or Scissors?"); //need to make sure only one of those three options are chosen
|
||||||
// const cs = getComputerChoice()
|
const cs = getComputerChoice();
|
||||||
|
|
||||||
//console.log(game(ps, cs)) -
|
//console.log(game(ps, cs))
|
||||||
|
console.log(ps +" " + cs)
|
||||||
Loading…
Reference in a new issue