功能不起作用

时间:2016-01-15 16:39:57

标签: javascript html

再次问好我的功能问题答案根本不起作用。假设提示切换命令。我用这个网站寻求帮助。 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 :
    	text = "Excellent choice! Whatever you said is good for your soul.";
        break;
    case keyword1:
    	text = robotAnswer1;
        break;
case keyword2:
    	text = robotAnswer2;
        break;
case keyword3:
    	text = robotAnswer3;
        break;
case keyword4: 
    	text = robotAnswer4;
        break;
case keyword5: 
    	text = robotAnswer5;
        break;
case keyword6:
    	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 :
    	text = "Excellent choice! Whatever you said is good for your soul.";
        break;
    case keyword1:
    	text = robotAnswer1;
        break;
case keyword2:
    	text = robotAnswer2;
        break;
case keyword3:
    	text = robotAnswer3;
        break;
case keyword4: 
    	text = robotAnswer4;
        break;
case keyword5: 
    	text = robotAnswer5;
        break;
case keyword6:
    	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>

1 个答案:

答案 0 :(得分:0)

首先,将function questionAnswer {替换为function questionAnswer () {

其次,您在}

结尾处错过function questionAnswer个关闭

第三,用"

替换所有'个实例

第四种情况,case :为空 - 在那里放一些值。

第五,正如mplungjan建议的那样,把表格放在身体里。

作为一般做法,请使用调试器测试您的HTML,例如,在Chrome中,按F12并刷新页面以查看是否有任何错误。

希望这有帮助