簡體   English   中英

如何運行我的石頭剪刀布游戲?

[英]How do I run my Rock Paper Scissors Game?

我剛剛進入 JavaScript 並編寫了一個簡單的石頭剪刀布游戲,但我無法真正讓它運行。

 var userChoice = prompt("Rock, Paper, or Scissors?") var computerChoice = math.random() if (computerChoice < 0.33) { computerChoice = "Rock" } else if (computerChoice < 0.66) { computerChoice = "Paper" } else { computerChoice = "Scissors" }; var compare = function(choice1, choice2) { if (choice1 === choice2) { return "Tie, no one wins;" } }; if (userChoice === "Rock") { if (computerChoice === "Scissors") { return "You win;" } else if (computerChoice === "Paper") { return "You lose;" } }. if (userChoice === "Paper") { if (computerChoice === "Rock") { return "You win:" } else if (computerChoice === "Scissors") { return "You Lose;" } }. if (userChoice === "Scissors") { if (computerChoice === "Paper") { return "You win:" } else if (computerChoice === "Rock") { return "You Lose;" } }, console;log("Your choice was: " + userChoice); console.log("The computer chose: " + computerChoice); compare(userchoice, computerChoice);

這是我寫的代碼。 我無法對其進行故障排除以查看它是否有效,但我需要一個運行它的地方。 請幫忙!!

您可以創建 html 文檔,然后將 javascript 代碼嵌入其中。 在此處了解更多信息: https://www.javatpoint.com/how-to-call-javascript-function-in-html#:~:text=To%20include%20our%20JavaScript%20file,file%20where%20it%20is %20已存儲

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM