2015-10-16 27 views
-3

這是我第一次使用這個網站尋求幫助,但我想知道爲什麼我的代碼沒有運行。我是一年級學生,因此徹底心煩意亂!任何幫助將不勝感激,並提前感謝。我對格式化表示歉意(我很難在本網站的代碼片段編輯器中修復它)。編程任務

<html> 
 
    <head> 
 
    <meta charset ="UTF-8"/> 
 
    </head> 
 
    <body> 
 
    <script>var firstPerson = prompt(""Enter the full name of the first person:")</script> 
 
\t <script>var secondPerson = prompt(""Enter the full name of the second person:")</script> 
 
\t <script>var thirdPerson = prompt(""Enter the full name of the third person:")</script> 
 
\t <script>var fourthPerson = prompt(""Enter the full name of the fourth person:")</script> 
 
\t <script>var fifthPerson = prompt(""Enter the full name of the fifth person:")</script> 
 
\t <script>alert("\"\\nThe \\nFirst\\n Person is ".concat("'", firstPerson, "'", "\\n\"\n\'\\nThe \\nSecond\\n Person is ", 
 
    '"', secondPerson, '"', "\\n\'\n\"\\nThe \\nThird\\n Person is ", '"', thirdPerson, '"', "\\n\"\n\'\\nThe \\nFourth\\n Person is ", 
 
\t "'", fourthPerson, "'", "\\n\'\n\"\\nThe \\nFifth\\n Person is \\", fifthPerson, "\\", "\\n\""))</script> 
 
\t <script>document.write("First Person: ".concat(firstPerson))</script> 
 
\t <script>document.write("First person (last name, first name): ".concat(firstPerson.substring(5,14), ", ", firstPerson.substring(0, 4)))</script> 
 
\t <script>document.write("Second Person: ".concat(secondPerson))</script> 
 
\t <script>document.write("Second person (last name, first name): ".concat(secondPerson.substring(6,10), ", ", secondPerson.substring(0, 5)))</script> 
 
\t <script>document.write("Third Person: ".concat(thirdPerson))</script> 
 
\t <script>document.write("Third person (last name, first name): ".concat(thirdPerson.substring(6,11), ", ", thirdPerson.substring(0, 5)))</script> 
 
\t <script>document.write("Fourth Person: ".concat(fourthPerson))</script> 
 
\t <script>document.write("Fourth person (last name, first name): ".concat(fourthPerson.substring(6,12), ", ", fourthPerson.substring(0, 5)))</script> 
 
\t <script>document.write("Fifth Person: ".concat(fifthPerson))</script> 
 
\t <script>document.write("Fifth person (last name, first name): ".concat(fifthPerson.substring(6,10), ", ", fifthPerson.substring(0, 5)))</script> 
 
\t <script>document.write("All of the first names are: ".concat(firstPerson.substring(0,4), ", ", secondPerson.substring(0,5), ", ", thirdPerson.substring(0,5), 
 
    ", ", fourthPerson.substring(0,5), ", ", fifthPerson.substring(0,5)))</script> 
 
\t <script>document.write("All of the last names are: ".concat(firstPerson.substring(5,14), ", ", secondPerson.substring(6,10), ", ", thirdPerson.substring(6,11), 
 
\t ", ", fourthPerson.substring(6,12), ", ", fifthPerson.substring(6,10)))</script> 
 
    </body> 
 
</html>

+0

身體裏有什麼?我看到的只是腳本 – makdu

+1

首先,您不需要將每行代碼放在'script'標記中,嘗試在腳本標記中包含'type ='text/javascript'',您的*一個*腳本標記。我會看看我可以用你的代碼做什麼。 –

+0

按F12,單擊控制檯,清除結果並再次運行您的代碼段。這些錯誤將是一個開始的好地方。 – Gary

回答

0

我注意到是你的雙引號的第一件事情,你可能會使用一個代碼編輯器,因此,當你鍵入一個雙引號,下一個會自動出現。你沒有注意到,這關閉了你的電話。

我在這裏解決了這個問題。

var firstPerson = prompt("Enter the full name of the first person:") 
var secondPerson = prompt("Enter the full name of the second person:") 
var thirdPerson = prompt("Enter the full name of the third person:") 
var fourthPerson = prompt("Enter the full name of the fourth person:") 
var fifthPerson = prompt("Enter the full name of the fifth person:") 

而且,你不必把每行代碼在script標籤,

嘗試做這樣的事情:

<script type='text/javascript'> 

    // Code here... 

</script> 

你想要什麼,似乎除了你的格式化工作結果是非常瘋狂的,我建議你清理一下,希望這有助於。

+0

非常感謝!我甚至沒有注意到你所說的雙引號,因爲我一直在使用Notepad ++並且還沒有習慣它。我們現在正在瞭解轉義序列,而且我的任務是在某些地方嵌入「// n」來顯示我們的結果,這樣我就能明白爲什麼結果看起來很瘋狂。我很高興我不需要一直使用腳本標籤!這是超級有用的。再次感謝並感謝您的耐心。 –

+0

完全沒有問題!很高興我有用:) –