Showing the same result in Rock Paper Scissors - Java Script - javascript

**I am trying to create rock paper scissors in java script and The below is the code I am executing, It is showing "The match is draw! play again" everytime. What goes wrong?
First taking the user input and checking the correctness. Generating the computer input by Math.random and assigning them RPS based on the output. Finally comparing both to determine the winner.**
const getUserChoice = function(userInput){
userInput = userInput.toLowerCase();
if (userInput === 'rock'|| userInput ==='paper'|| userInput ==='scissors'){
return userInput;
}else {
console.log('Error');
}
}
userChoice = getUserChoice('rock');
console.log(getUserChoice('rock'));
const getComputerChoice = function(){
randomNumber = Math.floor(Math.random()*3);
switch(randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'scissors';
break;
default:
return 'error';
}
}
computerChoice = getComputerChoice();
console.log(getComputerChoice());
const determineWinner = function(userChoice, computerChoice){
if (userChoice === computerChoice){
return 'The match is draw! Play again.';
}
if (userChoice === 'rock'){
if (computerChoice === 'paper'){
return 'you lost';
}else{
return 'you won';
}
}
if (userChoice === 'paper'){
if (computerChoice === 'rock'){
return 'you won';
}else{
return 'you lost';
}
}
if (userChoice === 'scissors'){
if (computerChoice === 'rock'){
return 'you lost';
}else{
return 'you won';
}
}
}
console.log(determineWinner());**strong text**

On your bottom line, you are not passing any parameters through.
Change it to:
console.log(determineWinner(userChoice, computerChoice));**strong text**
Currently, the first line of your determineWinner function is checking if null is equal to null (which it is), so is returning a draw.

Here you go. Checkout the below answer:
const getUserChoice = function(userInput){
userInput = userInput.toLowerCase();
if (userInput === 'rock'|| userInput ==='paper'|| userInput ==='scissors'){
return userInput;
}else {
console.log('Error');
}
}
const userChoice = getUserChoice('rock');
const getComputerChoice = function(){
const randomNumber = Math.floor(Math.random() * 3);
switch(randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'scissors';
break;
default:
return 'error';
}
}
const computerChoice = getComputerChoice();
const determineWinner = function(userChoice, computerChoice){
console.log('user choice: ', userChoice);
console.log('computer choice: ', computerChoice);
if (userChoice === computerChoice){
return 'The match is draw! Play again.';
}
if (userChoice === 'rock'){
if (computerChoice === 'paper'){
return 'you lost';
} else {
return 'you won';
}
}
if (userChoice === 'paper'){
if (computerChoice === 'rock'){
return 'you won';
}else{
return 'you lost';
}
}
if (userChoice === 'scissors'){
if (computerChoice === 'rock'){
return 'you lost';
}else{
return 'you won';
}
}
}
console.log(determineWinner(userChoice, computerChoice));

It's simply because you are not passing the arguments to the determineWinner function.
Change the last line to:
determineWinner(userChoice,computerChoice);
Currently it's considering both choices as null and returning you the output as draw!

Related

Getting tie always with Rock Paper Scissors game Javascript

const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput
} else {
console.log('Error!')
}
}
const getcomputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3)
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return 'Tie'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'computer won'
} else {
return 'user won'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'scissors') {
return 'computer won'
} else {
return 'user won'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'computer won'
} else {
return 'user won'
}
}
}
const playGame = () => {
var userChoice = getUserChoice()
console.log(userChoice)
var computerChoice = getcomputerChoice()
console.log(computerChoice)
console.log(determineWinner(userChoice, computerChoice))
}
console.log(determineWinner())
So I wanted to do a project with JS, was following codeacadem's course on the subject. But for some reason I am always getting a tie which I do not understand why. Can anyone please help me? I thought this is the correct code and every single object was working properly.
UPDATE:
After giving a parameter to the userchoice (getUserChoice('scissors')) I got this error: userInput = userInput.toLowerCase();
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
Initializing playgame didnt solve the issue
I've corrected your code with a few things:
As #James has commented, getUserChoice() expects a parameter for the choice of the user but none is given at playGame().
As #Alon Eitan has commented, console.log(determineWinner()) doesn't play the game at all as it just calls determineWinner() with the two parameters undefined. And actually that's why Tie is always returned as undefined == undefined.
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput
} else {
console.log('Error!')
}
}
const getcomputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3)
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return 'Tie'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'computer won'
} else {
return 'user won'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'scissors') {
return 'computer won'
} else {
return 'user won'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'computer won'
} else {
return 'user won'
}
}
}
const playGame = () => {
var userChoice = getUserChoice("rock")
console.log(userChoice)
var computerChoice = getcomputerChoice()
console.log(computerChoice)
console.log(determineWinner(userChoice, computerChoice))
}
playGame()

The variables inside the functions can't be called

I'm doing this rock, paper, and scissors game, however, my last function it's not working properly, it won't execute that block of code, and what it's wrong with the variables in the last function, they cannot be called, I've tried to change the parameters, I also debugged the code and to the extent I notice just the last function it's not working properly
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput == "rock" || userInput == "paper" || userInput == "scissors") {
return userInput;
} else {
console.log('Enter a valid option')
};
};
function getComputerChoice(any) {
return Math.floor(Math.random() * any)
}
switch (getComputerChoice(3)) //userInput
{
case 0:
console.log('rock');
break;
case 1:
console.log('paper');
break;
case 2:
console.log('scissors');
break;
default:
console.log('Select a valid option')
}
function determineWinner(getUserChoice, getComputerChoice) {
if (getUserChoice === getComputerChoice) {
return 'The game was a tie'
}
if (getUserChoice === 'rock') {
if (getComputerChoice === 'paper') {
return 'The computer won!'
} else {
return 'You won'
}
}
if (getUserChoice === 'scissors') {
if (getComputerChoice === 'rock') {
return 'Computer won!'
} else {
return 'You won!'
}
}
}
const playGam = () => {
const userChoice = getUserChoice('scissors');
const computerChoice = getComputerChoice();
console.log('You threw: ' + userChoice);
console.log('The computer threw: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGam();
As posted, getComputerChoice just does random math and multiplies by a (sometimes missing) param. Consider changing to return a random choice from the set of ['rock', 'paper', 'scissors']...
function getComputerChoice() {
const choices = ['rock', 'paper', 'scissors'];
return choices[Math.floor(Math.random() * choices.length)]
}
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput == "rock" || userInput == "paper" || userInput == "scissors") {
return userInput;
} else {
console.log('Enter a valid option')
};
};
function getComputerChoice() {
const choices = ['rock', 'paper', 'scissors'];
return choices[Math.floor(Math.random() * choices.length)]
}
switch (getComputerChoice(3)) //userInput
{
case 0:
console.log('rock');
break;
case 1:
console.log('paper');
break;
case 2:
console.log('scissors');
break;
default:
console.log('Select a valid option')
}
function determineWinner(getUserChoice, getComputerChoice) {
if (getUserChoice === getComputerChoice) {
return 'The game was a tie'
}
if (getUserChoice === 'rock') {
if (getComputerChoice === 'paper') {
return 'The computer won!'
} else {
return 'You won'
}
}
if (getUserChoice === 'scissors') {
if (getComputerChoice === 'rock') {
return 'Computer won!'
} else {
return 'You won!'
}
}
}
const playGam = () => {
const userChoice = getUserChoice('scissors');
const computerChoice = getComputerChoice();
console.log('You threw: ' + userChoice);
console.log('The computer threw: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGam();
We could also improve the code in a few other ways...
// make this global
const choices = ['rock', 'paper', 'scissors'];
const beats = { rock: 'scissors', scissors: 'paper', paper: 'rock' };
// general purpose fn to validate
const validateChoice = choice => {
return choices.includes(choice.toLowerCase());
};
// a tightly specified thing to determine winner
const determineWinner(userChoice, computerChoice) {
if (computerChoice === userChoice) return 'tie';
return beats[userChoice] === computerChoice ? 'user win' : 'computer win';
}
You're not setting a variable value with your swtich statement. You need to return what's the computer's choice, so I've put your switch statement inside the getComputerChoice function and then it returns the output and you can use it in your playGam function. I've updated that as well to display the winner in every outcome.
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput == "rock" || userInput == "paper" || userInput == "scissors") {
return userInput;
} else {
console.log('Enter a valid option')
};
};
function getComputerChoice(any) {
const randomNo = Math.floor(Math.random() * any)
switch (randomNo) //userInput
{
case 0:
return 'scissors';
break;
case 1:
return 'paper';
break;
case 2:
return 'rock';
break;
default:
return 'Select a valid option';
}
}
function determineWinner(getUserChoice, getComputerChoice) {
if (getUserChoice === getComputerChoice) {
return 'The game was a tie'
}
switch (getUserChoice) {
case 'paper':
return getComputerChoice === 'scissors' ? 'The computer won!' : 'You won';
case 'rock' :
return getComputerChoice === 'scissors' ? 'The computer won!' : 'You won';
case 'scissors' :
return getComputerChoice === 'paper' ? 'You won' : 'The computer won!';
default:
return 'Something went wrong'
}
}
const playGam = () => {
const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice(3);
console.log('You threw: ' + userChoice);
console.log('The computer threw: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGam();

JavaScript: rock paper scissors. Function error

im trying to create the game "rock, paper or scissors" in JavaScript, but im stuck on the last function "game()", it should repeat 5 times the function playRound() and throw a result each of those 5 times. But doesnt work.
function computerPlay(){
let optionsList = ["rock", "paper", "scissors"];
let option = optionsList[Math.floor(Math.random() * optionsList.length)];
return option
}
function playRound(playerSelection, computerSelection){
var playerSelection = prompt("Choose: rock, paper or scissors").toLowerCase();
var computerSelection = computerPlay();
if (playerSelection = "rock"){
switch(computerSelection){
case "rock":
return "T";
case "paper":
return "M";
case "scissors":
return "Y";
}
}else if (playerSelection = "paper"){
switch(computerSelection){
case "rock":
return "Y";
case "paper":
return "T";
case "scissors":
return "M";
}
}else if (playerSelection = "scissors"){
switch(computerSelection){
case "rock":
return "M";
case "paper":
return "Y";
case "scissors":
return "T";
}
}
}
function game(){
let i = 0
for(i=1; i<=5; i++){
playRound()
if (playRound()= "M") {
console.log("Machine Wins");
}else if (playRound() = "Y"){
console.log("You Win")
}else if (playRound() = "T"){
console.log("You Win!")
}
}
}
You have a couple errors:
The first is that you are trying to use the = operator to compare values. You need to use == or ===.
Secondly, you need to get the return value of playRound() and then check its value to determine the outcome of the game. But instead, you are calling playRound() initially in each iteration of your loop, and then again each time you try to determine the outcome.
Try:
function computerPlay() {
let optionsList = ["rock", "paper", "scissors"];
let option = optionsList[Math.floor(Math.random() * optionsList.length)];
return option
}
function playRound(playerSelection, computerSelection) {
var playerSelection = prompt("Choose: rock, paper or scissors").toLowerCase();
var computerSelection = computerPlay();
if (playerSelection === "rock") {
switch (computerSelection) {
case "rock":
return "T";
case "paper":
return "M";
case "scissors":
return "Y";
}
} else if (playerSelection === "paper") {
switch (computerSelection) {
case "rock":
return "Y";
case "paper":
return "T";
case "scissors":
return "M";
}
} else if (playerSelection === "scissors") {
switch (computerSelection) {
case "rock":
return "M";
case "paper":
return "Y";
case "scissors":
return "T";
}
}
}
function game() {
let i = 0
for (i = 1; i <= 5; i++) {
let outcome = playRound()
if (outcome === "M") {
console.log("Machine Wins");
} else if (outcome === "Y") {
console.log("You Win")
} else if (outcome === "T") {
console.log("You Win!")
}
}
}
game();
Not sure it this fixes the problem but here's a syntax error: = instead of ==. Also, you shouldn't call playRound() in every else. Just store the result in a variable.
let result = playRound()
if (result== "M") {
console.log("Machine Wins");
}else if (result == "Y"){
console.log("You Win")
}else if (result == "T"){
console.log("You Win!")
}

How to use function expression values in other functions?

I'm learning Javascript and I make a rock, scissors, paper project. I already make it work with the sample code but now I want to use a function expression to use its value in other functions. When I load the code it gave me undefined and I don't know why. I assign all the values.
Here is my code.
const userChoice = userInput => {
//userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput;
} else {
console.log('Error!');
}
}
//console.log(getUserChoice('Fork'));
const computerChoice = function() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors'
}
};
//console.log(getComputerChoice());
function determineWinner(userChoice, computerChoice) {
console.log()
if (userChoice === computerChoice) {
return 'The game is a tie!'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'bomb') {
return 'You won!';
}
}
const playGame = () => {
console.log('You threw: ' + userChoice('rock'));
console.log('The computer threw: ' + computerChoice());
console.log(determineWinner(userChoice, computerChoice));
}
playGame();
Please help me.
You're passing the function userChoice as a param, you should store the result of calling the function userChoice and pass the result as a param in the function determineWinner
const userChoice = userInput => {
//userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput;
} else {
console.log('Error!');
}
}
//console.log(getUserChoice('Fork'));
const computerChoice = function() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors'
}
};
//console.log(getComputerChoice());
function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return 'The game is a tie!'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'bomb') {
return 'You won!';
}
}
const playGame = () => {
let uc = userChoice('rock');
console.log('You threw: ' + uc);
console.log('The computer threw: ' + computerChoice());
console.log(determineWinner(uc, computerChoice));
}
playGame();
You should assign the outputs of userChoice and computerChoice to variables before passing them to determineWinner
const userChoice = userInput => {
//userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput;
} else {
console.log('Error!');
}
}
//console.log(getUserChoice('Fork'));
const computerChoice = function() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors'
}
};
//console.log(getComputerChoice());
function determineWinner(userChoice, computerChoice) {
console.log()
if (userChoice === computerChoice) {
return 'The game is a tie!'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'bomb') {
return 'You won!';
}
}
const playGame = () => {
const userChose = userChoice('rock')
const computerChose = computerChoice()
console.log('You threw: ' + userChose);
console.log('The computer threw: ' + computerChose);
console.log(determineWinner(userChose, computerChose));
}
playGame();
Try This
const userChoice = userInput => {
//userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput;
} else {
console.log('Error!');
}
}
//console.log(getUserChoice('Fork'));
const computerChoice = function() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors'
}
};
//console.log(getComputerChoice());
function determineWinner(userChoice, computerChoice) {
console.log()
if (userChoice === computerChoice) {
return 'The game is a tie!'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'bomb') {
return 'You won!';
}
}
const playGame = () => {
console.log('You threw: ' + userChoice('rock'));
console.log('The computer threw: ' + computerChoice());
console.log(determineWinner(userChoice('rock'), computerChoice()));
}
playGame();
just a few mistakes.
You need to store the values into variables.
const userChoice = userInput => {
//userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper' || userInput === 'bomb') {
return userInput;
} else {
console.log('Error!');
}
}
//console.log(getUserChoice('Fork'));
const computerChoice = function() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors'
}
};
//console.log(getComputerChoice());
function determineWinner(userChoice, computerChoice) {
console.log()
if (userChoice === computerChoice) {
return 'The game is a tie!'
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!'
}
}
if (userChoice === 'bomb') {
return 'You won!';
}
}
const playGame = () => {
const threw = {
computer: null,
user: null
}
threw.user = userChoice("rock")
threw.computer = computerChoice()
console.log('You threw: ' + threw.user);
console.log('The computer threw: ' + threw.computer);
console.log(determineWinner(userChoice(threw.user), threw.computer));
}
playGame();

Declaration or statement expected in If Statements

So I am working on some code to build a simple application in Javascript where the computer has a random number assigned to rock, paper, scissors and choose randomly and then has a userchoice as well. The code is not running not sure why.
I have tried adding semicolon to the end of the if statements that are inside the main if statement in the determineWinner function.
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
return userInput;
}else {
console.log('Error, you must type rock, paper, or scissors');
}
}
function getComputerChoice(){
var randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
function determineWinner(userChoice, computerChoice){
if(userChoice === computerChoice){
return 'This game is a tie!'
} else if(userChoice === 'rock'){
if(computerChoice === 'paper'){
return 'The computer has won!';
}else{
return 'The user has won';
}
} else if(userChoice === 'paper'){
if(computerChoice === 'scissors'){
return 'The computer has won!';
}else(computerChoice === 'rock');{
return 'The user has won!';
}
}else(userChoice === 'scissors');{
if(computerChoice === 'rock'){
return 'The computer has won!';
}else(computerChoice === 'paper');{
return 'The user has won!';
}
}
}
}
console.log(determineWinner('paper', 'scissors'));
When running the console.log at the end of the script it should display that the computer has won.
Since all of your if cases simply return, you don't need to use else since the if-case will always return. Like this:
function determineWinner(userChoice, computerChoice){
if (userChoice === computerChoice) {
return 'This game is a tie!'
}
if (userChoice === 'rock') {
if(computerChoice === 'paper') {
return 'The computer has won!';
}
return 'The user has won';
}
if (userChoice === 'paper') {
if(computerChoice === 'scissors'){
return 'The computer has won!';
}
return 'The user has won!';
}
if (userChoice === 'scissors') {
if(computerChoice === 'rock') {
return 'The computer has won!';
}
return 'The user has won!';
}
}
Another way is to just return at the end of the function with the answer like this:
function determineWinner(userChoice, computerChoice){
const results = [
'This game is a tie!',
'The computer has won!',
'The user has won!'
];
let winner;
if (userChoice === computerChoice) winner = 0;
else if (userChoice === 'rock') {
winner = computerChoice === 'paper' ? 1 : 2;
}
else if (userChoice === 'paper') {
winner = computerChoice === 'scissors' ? 1 : 2;
}
else if (userChoice === 'scissors') {
winner = computerChoice === 'rock' ? 1 : 2;
}
return results[winner];
}
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
return userInput;
}else {
console.log('Error, you must type rock, paper, or scissors');
}
}
function getComputerChoice(){
var randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
function determineWinner(userChoice, computerChoice){
if(userChoice === computerChoice){
return 'This game is a tie!'
} else if(userChoice === 'rock'){
if(computerChoice === 'paper'){
return 'The computer has won!';
}else if(computerChoice === 'scissors'){
return 'The user has won';
}
} else if(userChoice === 'paper'){
if(computerChoice === 'scissors'){
return 'The computer has won!';
}else if(computerChoice === 'rock'){
return 'The user has won!';
}
}else if(userChoice === 'scissors'){
if(computerChoice === 'rock'){
return 'The computer has won!';
}else if(computerChoice === 'paper'){
return 'The user has won!';
}
}
}
console.log(determineWinner('paper', 'scissors'));

Categories