javascript - How would you make the result print "computer wins" or "user wins" -
javascript - How would you make the result print "computer wins" or "user wins" -
obviously, print out rock/paper/scissors wins or it's tie.
what best way accomplish result "rock beats scissors -- computer wins!" , such?
var userchoice = prompt("do take 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) { homecoming "the result tie!"; } else if (choice1 === "rock") { if (choice2 === "scissors") { homecoming "rock wins"; } else { homecoming "paper wins"; } } else if (choice1 === "paper") { if (choice2 === "rock") { homecoming "paper wins"; } else { homecoming "scissors wins"; } } else if (choice1 === "scissors") { if (choice2 === "paper") { homecoming "scissors wins"; } else { homecoming "rock wins"; } } } compare(userchoice,computerchoice);
i have knowledge of functions , variables think plenty solve -- can't figure out. have less 8 hours of javascript experience.
also, not homework, finished lesson in codecademy , wondered this.
i changing strings in programme instead of "scissors wins" alter "scissors beats (insert corresponding selection here) - player wins!!!"
you can find corresponding selection trial , error debugging or next logic of nested if's , else's.
hope helps ;)
javascript
Comments
Post a Comment