I'm trying to compare three values randomly generated, but I can't quite seem to get it, I've tried every combination I can think of

$(document).ready(function() {

  $( "#click" ).click(function() {
    var image1 = new Array ();
    var number1 = 1 + Math.floor(Math.random() * 3);
    image1[0] = "<img src='images/ace.jpg'>";
    image1[1] = "<img src='images/king.png'>";
    image1[2] = "<img src='images/queen.png'>";

var image2 = new Array ();
var number2 = 1 + Math.floor(Math.random() * 3);
image2[0] = "<img src='images/ace.jpg'>";
image2[1] = "<img src='images/king.png'>";
image2[2] = "<img src='images/queen.png'>";

var image3 = new Array ();
var number3 = 1 + Math.floor(Math.random() * 3);
image3[0] = "<img src='images/ace.jpg'>";
image3[1] = "<img src='images/king.png'>";
image3[2] = "<img src='images/queen.png'>";

$('.one').html(image1[number1]);
$('.two').html(image2[number2]);
$('.three').html(image3[number3]);

if(number1 && number2 && number3 === number1 && number2 && number3){
  console.log("you win");
   $('.win').html("<h1>You win!!</h1>");
}
else{
  $('.win').html("<h1>Try again!!</h1>");
  console.log("You lose");
}

  });
});
    if(number1 && number2 && number3 === number1 && number2 && number3)

    (I wonder why I put this here).

    (I wonder what I meant).

    (Perhaps I was looking for an association?)

      $( "#click" ).click(function() {
          var image1 = new Array ();
          var number1 = 1 + Math.floor(Math.random() * 3);
          var one = $(".one"),
          two = $(".two"),
          three = $(".three");
          image1[0] = "<img src='images/ace.jpg'>";
          image1[1] = "<img src='images/king.png'>";
          image1[2] = "<img src='images/queen.png'>";
      
      $(one).html(image1[number1]);
      $(two).html(image1[number1]);
      $(three).html(image1[number1]);
      
      if(one && two && three === one && two && three){
        console.log("you win");
         $('.win').html("<h1>You win!!</h1>");
      }
      else{
        $('.win').html("<h1>Try again!!</h1>");
        console.log("You lose");
      }
      

      Well this maybe a little less ugly, although maybe "more" wrong but back to values and searching online values and associations

      nope

        Depending on what it is you're trying to compare (objects only compare identical to themselves), [font=monospace]a[/font], [font=monospace]b[/font], and [font=monospace]c[/font] are identical if [font=monospace]a === b && b === c[/font]. (Contrariwise, if [font=monospace]a[/font] and [font=monospace]b[/font] are different objects, then [font=monospace]a !== b[/font] even if they look identical, with identical properties.)

          Hi cluelessPHP,
          Since you are using the same set of images, it is enough if you compare number1, number2 and number 3. As weedpacket mentioned above, use if((number1==number2) && (number2==number3))

            Oh bugger I marked it as resolved and it doesn't work

               var number1 = Math.floor(Math.random() * 3); 
              

              Like that and it works, thanks all

                Write a Reply...