为什么 "else if" 在 console.log 中不起作用并不断弹出语法错误?

Why doesn't "else if" work in console.log and keeps popping syntax error?

我的控制台有问题。我想在 n<10 else if n<100 和 else 时加上控制台注释。好像它不会让我通过 else if。我试图找到答案,但没有任何效果。

let n = 14;
undefined
if (n<10){
  console.log("grats");}
undefined
else if (n<100){console.log("grats2");}
SyntaxError: expected expression, got keyword 'else'

在浏览器的控制台中,每一行似乎都是单独解释和执行的。当你关闭你的 if 的大括号时,如果你停在那里,那么表达式将被执行并且在下一行你不能去 else 因为 if 语句已经完成。

你能做的是

if (condition) {
  // ... operations
} else {

通过在关闭花括号后立即编写 else 你告诉控制台你还没有完成 if 语句