在 JavaScript 中切换意外标记
我在以下代码中发现了意外的标记。
switch ( hobby ) {
case =" painting ":
message = "Van Gogh was good at that.";
break;
case =" drawing ":
message = "Hey! Van Gogh did that too.";
break;
case =" playing guitar ":
message = "Bob Dylan played guitar.";
break;
case =" sleeping in ":
message = "My favorite hobby in the winter.";
break;
default
}
有人看到我缺少什么吗?
I am finding an unexpected token in the following code.
switch ( hobby ) {
case =" painting ":
message = "Van Gogh was good at that.";
break;
case =" drawing ":
message = "Hey! Van Gogh did that too.";
break;
case =" playing guitar ":
message = "Bob Dylan played guitar.";
break;
case =" sleeping in ":
message = "My favorite hobby in the winter.";
break;
default
}
Does anyone see what I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的语法已经关闭。删除
case
后面的=
。此外,您还需要在default
之后添加:
。有关
switch
语句的更多信息,请参阅此处。Your syntax is off. Remove the
=
aftercase
s. Also, you'll need to put a:
afterdefault
.See here for more about
switch
statements.您可以利用函数语义来避免必须
break
脱离每个case
:不过,表达此逻辑的最佳方式可能如下所示:
You can take advantage of function semantics to avoid having to
break
out of eachcase
:The best way to express this logic, though, is probably something like the following: