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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -