comparison - Comparing strings with logical operators in an IF statement -
i trying figure out how compare strings within if statement. of code can ignored, there context. trying add message simple rock, paper, scissors game when enters string besides rock, paper, or scissors. can tell me doign wrong in portion asterisks around it?
var userchoice = prompt("do choose rock, paper or scissors?"); var computerchoice = math.random(); if (computerchoice < 0.34) { computerchoice = "rock"; } else if(computerchoice <= 0.67) { computerchoice = "paper"; } else { computerchoice = "scissors"; } console.log("computer: " + computerchoice); var compare = function (choice1, choice2) { if (choice1 === choice2) { return "the result tie!"; } **else if (choice1 !== "rock" || "paper" || "scissors") { return "your options rock, paper, or scissors friggin plebian!"; }** else if (choice1 === "rock") { if (choice2 === "scissors") { return "rock wins!"; } else { return "paper wins!"; } } else if (choice1 === "paper") { if (choice2 === "rock") { return "paper wins!"; } else { return "scissors wins!"; } } else if (choice1 === "scissors") { if (choice2 === "paper") { return "scissors wins!"; } else { return "rock wins!"; } }
};
compare (userchoice, computerchoice);
// ... else if (choice1 !== "rock" || choice1 !== "paper" || choice1 !== "scissors") { return "your options rock, paper, or scissors friggin plebian!"; } // ...
boolean expressions don't read might in english, i.e. "choice not rock or paper or scissors". evaluating "choice" boolean syntactically valid thing in languages, take care in remembering stupidly repeat parameter. otherwise these types of mistakes take while find. ;)
Comments
Post a Comment