If and else if loop

Trying to create a simple rock,paper,scissor game using if loop as below; but the console always return ‘Its a tie…’

Any advice on this would be much appreciated!

const player = {
  playerChoice: null
}
const computer = {
  computerChoice: null
};

const choices = ["Lapis", "Papyrus", "Scalpellus"];

const randomIndex = Math.floor(Math.random() * choices.length);

computer.computerChoice = choices[randomIndex];
player.playerChoice = choices[randomIndex];

if (computer.computerChoice === player.playerChoice) {
  console.log("It's a tie, both computer and player chose the same");
} else if (computer.computerChoice === choices[0] && player.playerChoice === choices[1]) {
  console.log("The player wins! The player chose Papyrus and the computer chose Lapis");
} else if (computer.computerChoice === choices[1] && player.playerChoice === choices[2]) {
  console.log("The player wins! The player chose Scalpellus and the computer chose Papyrus");
} else if (computer.computerChoice === choices[2] && player.playerChoice === choices[0]) {
  console.log("The player wins! The player chose Lapis and the computer chose Scalpellus");
} else { console.log("The computer wins! The player chose " + player.playerChoice + " and the computer chose " + computer.computerChoice) 
       }

First thing to do is use console.log right after the line that creates the random choice to print out the number created.

Then if I am surprised by the output I would read this

Let me know if you need more help.

It works now, thanks man for the help!

1 Like