Javascript If Condition with multiple OR and AND

前端 未结 7 851
谎友^
谎友^ 2020-12-22 07:33

please have a look on my if condition. I am just refreshing my javascript and I am wondering, how I could check, if the inserted variables, are the ones I want to be used.

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 08:03

    function compare(choice1, choice2){
      var identical = choice1 === choice2;
      var options = ["rock", "paper", "scissors"];
    
      if (identical && (options.indexOf(choice1) > -1))
        alert("Pass");
      else
        alert("Not alike");
    
    }
    

    In this code, identical will be either true or false, and if it is true, you can check if it matches any of the values inside the options array.

提交回复
热议问题