var feedback = prompt("rate the game 1-10");
if (feedback < 8) {
console.log("This is just the beginning of my game empire. Stay tuned for more!");
} else (feedback > 8) {
console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
}
答案 0 :(得分:4)
否则不应该有条件:) 你的比较似乎落后了;) 10我认为通常是高分!
答案 1 :(得分:2)
应该是else if(feedback > 8)
!
答案 2 :(得分:0)
如果你想在if-then-else块中测试另一个条件,你需要另一个if。
if (feedback < 8) {
console.log("This is just the beginning of my game empire. Stay tuned for more!");
} else {
if (feedback > 8) {
console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
} else {
// What about feedback == 8?
}
}
答案 3 :(得分:0)
您需要添加另一个if或delete de second条件。另外,检查插入值会很好。
此
if (feedback < 8) {/* Stuff */}
else {/* other stuff */}
或者
if (feedback < 8) {/* Stuff */}
else if (feedback > 8) {/* other stuff */}
您还应该检查输入值
function feedback () {
checkFeedback(prompt('rate the game 1-10'))
}
function checkFeedback (fdb) {
parsed = parseInt(fdb);
if (typeof(parsed) != 'number' || parsed < 1 || parsed > 10) {
alert('Number between 1 and 10 needed');
feedback();
}
else logMessage(parsed);
}
function logMessage(feedback) {
if (feedback<8)
console.log('This is just the beginning of my game empire. Stay tuned for more!')
else
console.log('I slaved away at this game and you gave me that score?! The nerve! Just you wait!')
}
feedback();