2013-12-18 72 views
0

我正在通過Codecademy試圖學習Javascript。當我到達紙/搖滾/剪刀部分時,我想出了一些代碼來展示我的朋友。這不是一個真正的遊戲。我讓它變得有趣。無論如何,我在Codecademy中寫了它,它工作。然後我複製/粘貼到textedit(我使用的是mac/safari),我添加的都是響應的標題標籤。但是現在提示不起作用。幫助noob。爲什麼不提示工作?

<!DOCTYPE html> 
<html> 
<body> 
<h1> 
Rock. Paper. Scissors. 
</h1> 
<script> 

var yourChoice = prompt("Choose your weapons: Rock, paper, or scissors.") 

if(yourChoice === "rock") 
document.write("<h1 style='text-align:center;font-size:50;'>Ha! I defeated you with the cunning of paper!</h1>") 

if(yourChoice === "paper") 
document.write("<h1 style='text-align:center;font-size:50;'>Muahaha! I have cut you down with the villanny of scissors!"</h1>) 

if(yourChoice === "scissors") 
document.write("<h1 style='text-align:center;font-size:50;'>Go and weep! For I have crushed your devilish scissors with the might of my rock!"</h1>) 

</script> 
</body> 
</html> 

希望這不是超級明顯的,我只是因爲某種原因失明。謝謝你,提前。

+0

我剛看到一個複製/粘貼問題。 – Euroclydon37

回答

2

你放錯地方的收盤"兩次:

if(yourChoice === "paper") 
    document.write("<h1 style='text-align:center;font-size:50;'>Muahaha! I have cut you down with the villanny of scissors!</h1>") 

if(yourChoice === "scissors") 
    document.write("<h1 style='text-align:center;font-size:50;'>Go and weep! For I have crushed your devilish scissors with the might of my rock!</h1>") 

Try it

+0

這解決了它。謝謝。 – Euroclydon37

0

試試這個:

<body onload="onLoad()"> 
    <script> 

    function onLoad() { 
     var yourChoice = prompt("Choose your weapons: Rock, paper, or scissors.") 

     if(yourChoice === "rock") 
    document.write("<h1 style='text-align:center;font-size:50;'>Ha! I defeated you with the cunning of paper!</h1>") 

     if(yourChoice === "paper") 
    document.write("<h1 style='text-align:center;font-size:50;'>Muahaha! I have cut you down with the villanny of scissors!</h1>") 

     if(yourChoice === "scissors") 
    document.write("<h1 style='text-align:center;font-size:50;'>Go and weep! For I have crushed your devilish scissors with the might of my rock!</h1>") 
    } 
    </script> 
0

你把收"在錯誤的地方...

if(yourChoice === "paper") 
document.write("<h1 style='text-align:center;font-size:50;'>Muahaha! I have cut you down with the villanny of scissors!</h1>") 

if(yourChoice === "scissors") 
document.write("<h1 style='text-align:center;font-size:50;'>Go and weep! For I have crushed your devilish scissors with the might of my rock!</h1>") 

使用語法高亮......這是被發現最簡單的方法。您還應該學習在瀏覽器中查看您的JavaScript控制檯是否有錯誤。這尤其扔了:

Uncaught SyntaxError: Invalid regular expression: missing /

儘管這不是確切的錯誤,它通常提供線索,以其中可能撒謊。