From 1f986c09e7487427e1a4705770bc1df838741d33 Mon Sep 17 00:00:00 2001 From: lolabird Date: Sat, 30 Sep 2023 10:47:14 -0600 Subject: [PATCH] Write playRound function and successfully test it --- script.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/script.js b/script.js index 26732f8..c553328 100644 --- a/script.js +++ b/script.js @@ -11,14 +11,33 @@ function getComputerChoice(){ } function playRound(playerSelection, computerSelection){ - //p = playerSelection.toLowerCase() - //c = computerSelection.toLowerCase() + p = playerSelection.toLowerCase(); + c = computerSelection.toLowerCase(); - // if player && comp === "rock", || if p && c === "paper" || p && c === "scissors" return "tie" - - //else if p === "rock" - //if c === "paper" player loses - //else if c === "scissors" player wins + if (p === c) { + return "tie"; + } else if (p === "rock") { + if (c === "paper") { + return "player loses"; + } else { //scissors + return "player wins" + } + } else if (p === "paper") { + if (c === "scissors") { + return "player loses"; + } else { //rock + return "player wins" + } + } else if (p === "scissors") { + if (c === "paper") { + return "player loses"; + } else { //scissors + return "player wins" + } + } else { + return "not a valid entry" + } + //else if p === "paper" //if c === "scissors" player loses //if c === "rock" player wins @@ -43,4 +62,4 @@ const ps = prompt("Rock, Paper or Scissors?"); //need to make sure only one of t const cs = getComputerChoice(); //console.log(game(ps, cs)) -console.log(ps +" " + cs) \ No newline at end of file +console.log(playRound(ps, cs)); \ No newline at end of file