jeudi 29 mars 2018

Javascript if statement only returns true

I am writing a rock paper scissors game.

console.log for the player shows the selected value.

console.log for the computer shows the selected value.

The if statement to check if the values match always returns true, even if the console log shows them to be different.

I have tried writing it a few different ways but always end up with this issue.

// Player Choice Selection 
var player = function() {
  const playerSelects = "rock";
  return playerSelects;
};
console.log(player());

// Computer Choice Selection
var computer = function() {
  const computerSelects = ['rock', 'paper', 'scissors'];
  let randomSelection = Math.floor(Math.random() * 3);
  return computerSelects[randomSelection];
};
console.log(computer());

// Game 
var game = function(player, computer) {
  if (player == computer) {
    const draw = "its a draw";
    return draw;
  }
};
console.log(game());

Can anyone tell me where I am going wrong with this?

Thanks

Aucun commentaire:

Enregistrer un commentaire