2013-03-27 71 views
0

我不知道为什么我得到这个错误。缺少操作数;发现END

missing operand; found END 

每当我做一个新行,它出现在底部,所以现在它说最后一行有问题。

这里是我的代码:

alert("Hello, and welcome to [title undecided] by ARADPLAUG!"); 
alert("If there's a yes or no question, just say yes or no, no nah's or sure's or yup's or anything like that."); 
alert("You have four stat points to begin with. If you enter something wrong, you get -1 stat point."); 
var choice1 = prompt("Choose one perk: STRENGTH, INTELLIGENCE, ENDURANCE, ALERTNESS or SPEED.").toLowerCase(); 
var choice2 = prompt("Choose one perk: STRENGTH, INTELLIGENCE, ENDURANCE, ALERTNESS or SPEED.").toLowerCase(); 
var choice3 = prompt("Choose one perk: STRENGTH, INTELLIGENCE, ENDURANCE, ALERTNESS or SPEED.").toLowerCase(); 
var beginning = prompt("You're running from a fire when you suddenly see a lake. Do you JUMP in it, keep RUNning, or FILL a bucket with it?").toLowerCase(); 
switch (beginning) { 
    case 'run': 
     alert("You run away from the scary water, into the safety of the fire. -YOU HAVE DIED-"); 
     break; 
    case 'fill': 
     var bucket = prompt("You have two buckets. Do you want to fill ONE or BOTH of them with water?").toLowerCase(); 
     break; 
    case 'jump': 
     if (choice1 === "alertness" || choice2 === "alertness" || choice3 === "alertness") { 
      var branch = prompt("You jump into the water just in time. A branch above you looks like it's about to fall off. Do you want to SHAKE it off now and be alert or WAIT and hope it won't fall off?").toLowerCase(); 
     } else if (choice1 || choice2 || choice3 === "speed") { 
      var cave = prompt("You jump out of the way just before a branch crushes you. It uncovers a hole leading to a cave. Do you enter it?"); 
     } else { 
      alert("You look up, and see the branch fall just before it crushes your neck, killing you instantly. -YOU HAVE DIED- "); 
     } 
     break; 
    default: 
     alert("Sorry, that wasn't one of the options. The fire consumes you. -YOU HAVE DIED-"); 
     switch (branch) { 
      case 'wait': 
       if (choice1 === "speed" || choice2 === "speed" || choice3 === "speed") { 
        prompt("You jump out of the way just before the branch crushes you. It uncovers a hole leading to a cave. Do you enter it?"); 
       } else { 
        alert("You look up, and see the branch fall just before it crushes your neck, killing you instantly. -YOU HAVE DIED- "); 
       } 
       break; 
      case 'shake': 
       var cave2 = prompt("You shake the branch, causing it to fall. It uncovers a hole. Do you enter it?"); 
       break; 
      default: 
       alert("That wasn't one of the options. The branch falls and crushes you. -YOU HAVE DIED-"); 
+0

你错过了'}'。 – Rudie 2013-03-27 12:49:56

+1

只需在终端添加'}}'。 – Vucko 2013-03-27 12:53:35

+0

除了答案。调试类似的工具之一就是[** jsFiddle **](http://jsfiddle.net)。您可以将您的代码复制到脚本部分,然后单击'JSHint'按钮,您可以看到'Missing'}''消息,并且该行的左边有一个红点。这是一个很棒的工具,对我有很大帮助,特别是它的自动格式化功能'TidyUp'非常适合寻找缺失的大括号和类似内容。 – Nope 2013-03-27 12:53:52

回答

2

你缺少}关闭您switch{...}块。 “意外的$end”通常意味着您的括号/圆括号/括号不能正确关闭。

+0

+1。我认为外层交换机也缺少一个。可能需要添加第二个'}'。但我可能是错的。 – Nope 2013-03-27 12:56:54

+0

谢谢,这有帮助! – ARADPLAUG 2013-03-27 20:10:34

0

我不是一个javascript的家伙,但你的开关被打开{,你是不是有一个匹配的结束}