javascript上出现错误.创造一个文字游戏
getting an error on javascript. creating a word game
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!");
}
else后面不应该有条件:)而且你的比较似乎是落后的;)我认为通常是10分的高分!
应该是else if(feedback > 8)
!
如果你想在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?
}
}
您需要添加另一个if或删除第二个条件。此外,检查插入值也不错。
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();
相关文章:
- 使用React创建一个100K的多人互动游戏
- 为基于Canvas和jQuery的游戏添加一个结束屏幕
- 缺少文字游戏(填充空白)
- VueJS组件来运行一个MelonJS游戏
- 结束一个反应游戏Javascript
- 做一个HTML游戏式的东西
- Javascript文字游戏
- 我如何用正则表达式在标签内找到一个文字字符串
- javascript上出现错误.创造一个文字游戏
- Javascript文字游戏如何使函数不替换元素
- 乱码文字游戏使用jQuery ui-排序
- 碰撞检测在一个吨游戏通过颜色
- 在文字游戏中使用数组
- 在Netbeans中创建一个乒乓游戏
- 我正在用JavaScript制作一个绞刑游戏,我很困惑
- 创造一个BINGO游戏
- 我在HTML设计一个国际象棋游戏,我想改变一个字符从一个位置到另一个
- 在Javascript上创建一个预测游戏
- 如何实现一个相位游戏到一个特定的页面在离子
- 你好,我正在做一个记忆游戏与javascript