varuserchoice=prompt("pleasechooseRockPaperorScissor!");varpcchoice=Math.random();switch(pcchoice){case(pcchoice<=0.33):pcchoice='rock';break;case(pcchoice>0.33&&pcchoice<=0.66):pcchoice='paper';break;default:pcchoice='scissor';}functionrockGame(userchoice){console.log(userchoice);console.log(pcchoice);if(userchoice===pcchoice){console.log('Tie!');}elseif(userchoice==='rock'){if(pcchoice==='scissor'){console.log('Youwin!');}else{console.log('PCwin!');}}elseif(userchoice==='scissor'){if(pcchoice==='paper'){console.log('Youwin!');}else{console.log('PCwin!');}}elseif(userchoice==='paper'){if(pcchoice==='rock'){console.log('Youwin!');}else{console.log('PCwin!');}}else{console.log('输入错误!');}}rockGame();
相关分类