嗨,我是JavaScript和一般编程的新手。我一直在使用Codecademy来帮助我学习。不过,我最近遇到了一个Codecademy中创建的一组代码的问题,我似乎无法找到问题所在。下面的代码:JavaScript和编程新手。我的代码错误?
var mInQuestion = prompt('Do you play a musical instrument?').toLowerCase;
if (mInQuestion == yes) {
var musInstrument = prompt('Which instrument do you play?').toLowerCase;
switch (musInstrument) {
case 'piano':
console.log('Oh great! Piano is wonderful!');
break;
case 'guitar':
console.log('Wow I love guitar as well!');
experience = prompt('Did you play when you were little?').toLowerCase;
interest = prompt('And do you like playing it?')toLowerCase;
if (experience && interest == yes||y) {
console.log("That's great! You must be a guitar master!");
}
else {
console.log("Keep learning! It will be great. Or you could do piano?");
}
break;
case 'flute':
console.log('Oh that\'s cool! You know I used to play flute as well!');
break;
default:
console.log('Oh I\'m not sure I\'ve heard of that instrument...sorry');
break;
}
else if (mInQuestion == no) {
console.log('Oh you don\'t? You should pick one like the piano or the guitar!');
}
else {
console.log('Your answer doesn\'t make sense...');
}
你能描述的期望输出与实际输出? – MannfromReno
唯一的输出我得到是: SyntaxError:意外标识符 – AZNPNOY2000
您需要为yes和no定义变量,或者将th em在引号中(“是”,“否”)。在case语句之后,你还缺少一个右括号。 – nril