所以,我目前正在学习控制流程,我必须用else if condition构建一个程序。问题是我不断收到 else if 的错误:"期望一个标识符并看到其他"和"期望一个 assigment 或函数调用,而是看到一个表达式"。代码如下:
var moonPhase = 'full';
if (moonPhase === 'full') {
console.log(Howwwlll!');}
else if (moonPhase === 'mostly full'); {
console.log('Arms and legs are getting hairier.');
} else if (moonPhase === 'mostly new'); {
console.log('Back on two feet');
} else {
console.log(Caution, unknown ');}
那我做错了什么?提前感谢!
删除 if 和 else 条件中的;
。 而且console.log()
有一个语法错误,你缺少一个'
单引号开头的语法错误
var moonPhase = 'full';
if (moonPhase === 'full') {
console.log('Howwwlll!');
} else if (moonPhase === 'mostly full'){
console.log('Arms and legs are getting hairier.');
} else if (moonPhase === 'mostly new'){
console.log('Back on two feet');
} else {
console.log('Caution, unknown');
}