所以我目前正在从 codecademy.com 学习 javascript ,我在尝试解决有关控制流的代码时遇到了问题
So i'm currently learning javascript from codecademy.com , i have got a issue trying to solve a code about control flow
所以,我目前正在学习控制流,我必须构建一个带有 else if 条件的程序。问题是我不断收到 else ifs 的错误:"Expected an identifier and saw else" 和 "Expected an assigment or function call and instead saw an expression"。这是代码:
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');
}
所以,我目前正在学习控制流,我必须构建一个带有 else if 条件的程序。问题是我不断收到 else ifs 的错误:"Expected an identifier and saw else" 和 "Expected an assigment or function call and instead saw an expression"。这是代码:
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');
}