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!");
}
user2288648
问问题
99 次
4 回答
4
else 后面不应该有条件 :) 而且你的比较似乎倒退了 ;) 10 我认为通常是高分!
于 2013-04-17T00:43:14.493 回答
2
应该是else if(feedback > 8)
!
于 2013-04-17T00:45:06.067 回答
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?
}
}
于 2013-04-17T00:44:48.297 回答
0
您需要放置另一个 if 或 delete de 第二个条件。检查插入值也很好。
这个
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();
于 2013-04-17T01:07:18.590 回答