应该有一个标识符,但是看到了“ else”

时间:2018-07-16 14:02:30

标签: javascript if-statement

过去一个小时,我一直在为此绞尽脑汁。看过有人问同样问题的例子,但错误是持久的。谁能检查我的代码,看看有什么问题吗?它是Udacity Java语言入门课程的一部分。错误出在ELSE线上,但老实说我没有发现任何错误。

var num = 60;

while (num => 0)
  if (num === 50) {
    console.log("Orbiter transfer from ground to internal power");
  }
elseif(num === 31); {
  console.log("Ground launch sequencer is go for auto sequence start");
}
elseif(num === 16); {
  console.log("Activate launch pad sound suppression system");
}
elseif(num === 10); {
  console.log("Activate main engine hydrogen burnoff system");
}
elseif(num === 6); {
  console.log("Main engine start");
}
elseif(num === 0); {
  console.log("Solid rocket booster ignition and liftoff!");
} else {
  console.log("T- " + num + " seconds");
}
num--;

1 个答案:

答案 0 :(得分:2)

您需要检查以下代码:

  • 正文必须在方括号{}之间
  • 删除“;”在其他条件之后
  • 条件必须为> =而不是=>
  • 否则为两个词

var num = 60;

while (num >= 0){
  if (num === 50) {
    console.log("Orbiter transfer from ground to internal power");
  }
else if(num === 31) {
  console.log("Ground launch sequencer is go for auto sequence start");
}
else if(num === 16) {
  console.log("Activate launch pad sound suppression system");
}
else if(num === 10) {
  console.log("Activate main engine hydrogen burnoff system");
}
else if(num === 6) {
  console.log("Main engine start");
}
else if(num === 0) {
  console.log("Solid rocket booster ignition and liftoff!");
} else {
  console.log("T- " + num + " seconds");
}
num--;
}