2016-01-15 199 views
-4

你好,我再次問我的功能questionAnswer根本不工作,它是假設提示開關命令。我用這個網站尋求幫助。 http://www.w3schools.com/jsref/met_win_prompt.asp功能不能正常工作

var keyword1 = "how are" 
 
var keyword2 = "what are" 
 
var keyword3 = "creator" 
 
var keyword4 = "why" 
 
var keyword5 = "how did" 
 
var keyword6 = "Where were" 
 
var keyword7 = "what do" 
 
var keyword8 = "color" 
 
var keyword9 = "Bye" 
 
var keyword10 = "animal" 
 
var keyword11 = "Hello" 
 

 
var robotAnswer1 = "Good" 
 
var robotAnswer2 = "I am the new Lego 「Dames」 droid 7.0. I am the newest and most advanced robot in this century!" 
 
var robotAnswer3 = "My creator is James Day, I was programmed by Emanuel 「Kiwi Elefant」 Rotible" 
 
var robotAnswer4 = "I was made to inspire imagination and bring smiles!" 
 
var robotAnswer5 = "I was created with state-of-the-art technology in a lab." 
 
var robotAnswer6 = "In a lab at Lego’s Headquarters" 
 
var robotAnswer7 = "I can talk, move listen, respond and can teach programming to kids" 
 
var robotAnswer8 = "I do not know what you are trying to say" 
 
var robotAnswer9 = "I was made to inspire imagination and bring smiles" 
 
var robotAnswer10 = "I was created with state-of-the-art technology in a lab" 
 
var robotAnswer11 = "In a lab at lego's Headquarters" 
 

 
function questionAnswer() { 
 
var text; 
 
var questionAnswer = prompt(「Ask me a Question!」); 
 
switch(questionAnswer) { 
 
    case questionAnswer : 
 
    \t text = "Excellent choice! Whatever you said is good for your soul."; 
 
     break; 
 
    case keyword1: 
 
    \t text = robotAnswer1; 
 
     break; 
 
case keyword2: 
 
    \t text = robotAnswer2; 
 
     break; 
 
case keyword3: 
 
    \t text = robotAnswer3; 
 
     break; 
 
case keyword4: 
 
    \t text = robotAnswer4; 
 
     break; 
 
case keyword5: 
 
    \t text = robotAnswer5; 
 
     break; 
 
case keyword6: 
 
    \t text = robotAnswer6; 
 
     break; 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
< script> 
 
var keyword1 = "how are" 
 
var keyword2 = "what are" 
 
var keyword3 = "creator" 
 
var keyword4 = "why" 
 
var keyword5 = "how did" 
 
var keyword6 = "Where were" 
 
var keyword7 = "what do" 
 
var keyword8 = "color" 
 
var keyword9 = "Bye" 
 
var keyword10 = "animal" 
 
var keyword11 = "Hello" 
 

 
var robotAnswer1 = "Good" 
 
var robotAnswer2 = "I am the new Lego 「Dames」 droid 7.0. I am the newest and most advanced robot in this century!" 
 
var robotAnswer3 = "My creator is James Day, I was programmed by Emanuel 「Kiwi Elefant」 Rotible" 
 
var robotAnswer4 = "I was made to inspire imagination and bring smiles!" 
 
var robotAnswer5 = "I was created with state-of-the-art technology in a lab." 
 
var robotAnswer6 = "In a lab at Lego’s Headquarters" 
 
var robotAnswer7 = "I can talk, move listen, respond and can teach programming to kids" 
 
var robotAnswer8 = "I do not know what you are trying to say" 
 
var robotAnswer9 = "I was made to inspire imagination and bring smiles" 
 
var robotAnswer10 = "I was created with state-of-the-art technology in a lab" 
 
var robotAnswer11 = "In a lab at lego's Headquarters" 
 

 
function questionAnswer() { 
 
var text; 
 
var questionAnswer = prompt(「Ask me a Question!」); 
 
switch(questionAnswer) { 
 
    case questionAnswer : 
 
    \t text = "Excellent choice! Whatever you said is good for your soul."; 
 
     break; 
 
    case keyword1: 
 
    \t text = robotAnswer1; 
 
     break; 
 
case keyword2: 
 
    \t text = robotAnswer2; 
 
     break; 
 
case keyword3: 
 
    \t text = robotAnswer3; 
 
     break; 
 
case keyword4: 
 
    \t text = robotAnswer4; 
 
     break; 
 
case keyword5: 
 
    \t text = robotAnswer5; 
 
     break; 
 
case keyword6: 
 
    \t text = robotAnswer6; 
 
     break; 
 
} 
 
</head> 
 
<body> 
 
    <title> Robot interaction </Title> 
 
    <base target="_top"> 
 
    <img class="irc_mi" style="margin-top: 2px;" src="http://engineering.missouri.edu/wp-content/uploads/Lego-Robot.jpeg" width="304" height="390"> 
 

 
    </script> 
 
</form> 
 

 
</body> 
 

 

 
<button onclick ="questionAnswer();">Ask</button> 
 
</script> 
 
    
 

 

 

 

 

 
<body> 
 
<script> 
 

 
</body> 
 

 

 
</html>

+0

你檢查過控制檯嗎?你的代碼有一個問題:'。 – Rajesh

+0

我認爲你會發現你的問題在於空殼, ...案例:\t text =「凱越...,你有沒有嘗試用devtools進行調試? – MCMXCII

+1

爲什麼在HEAD中有表格? – mplungjan

回答

0

首先,function questionAnswer() {

二取代function questionAnswer {,你錯過了在function questionAnswer

三月底}封閉,與"全部更換實例或'

第一種情況下,第一種情況下,case :是空的 - 在那裏放一些價值。

第五,如mplungjan建議,將表單放在正文中。

作爲一般的做法,請使用調試器測試您的html,例如在Chrome中,按F12並刷新頁面以查看是否有任何錯誤。

希望這會有幫助

+0

和第六,因爲文本不在任何地方使用「計算」值將簡單地變成撇號DED。目前沒有輸出。 – Thomas

+0

好的@Thomas,讓我們假設代碼的邏輯將被繼續。 – remdevtec

+0

非常感謝! –