[英]In Javascript, my onEvent isn't being called, while other onEvents are
I'm currently creating a blackjack game. 我正在制作一个二十一点游戏。 In my game, when the user clicks "Stay", the program is suppose to find who is closer to 21, the user or the house.
在我的游戏中,当用户点击“停留”时,该程序假设找到谁更接近21,用户或房子。 When I click stay, nothing occurs in my program.
当我点击停留时,我的程序中没有任何内容。 Any help will be appreciated.
任何帮助将不胜感激。 Thanks for reading.
谢谢阅读。
onEvent("stayButton","clicked", function() {
if (userTotal == 21) {
setText("userArea","Player total is: " + userTotal +" Player wins!");
}
houseTotal();
while (houseTotal < 17) {
appendItem( houseHand,deck.pop() );
houseHandTotal();
}
if (houseTotal > 21) {
setText("houseArea","House busts, User wins");
var userWins = betAmount * 1.2;
TotalMoney = TotalMoney + userWins;
}
setText("houseArea",houseHand + "house total is: " + houseTotal);
if ( 21 - userTotal < 21-houseTotal && userHandValue != "bust" && houseHandValue != "bust")
{
setText("userArea","Player total is: " + userTotal +" Player wins!");
}
else if (21 - userTotal > 21-houseTotal && userHandValue != "bust" && houseHandValue != "bust")
{
setText("userArea","Player total is: " + userTotal +" Player loses!");
}
});
Assuming onEvent
is a wrapper for addEventListener
, then the proper event name is click
, not clicked
. 假设
onEvent
是addEventListener
的包装器,则click
正确的事件名称,而不是clicked
。
Other minor clean up points: 其他小清理点:
===
and !==
for equality comparisons instead of ==
and !=
to avoid type conversion related nuances. ===
和!==
进行相等比较而不是==
和!=
以避免与类型转换相关的细微差别。 '
. '
单引号。 onEvent('stayButton', 'click', () => {
if (userTotal === 21)
setText('userArea', 'Player total is: ' + userTotal + ' Player wins!');
houseTotal();
while (houseTotal < 17) {
appendItem(houseHand, deck.pop());
houseHandTotal();
}
if (houseTotal > 21) {
setText('houseArea', 'House busts, User wins');
let userWins = betAmount * 1.2;
TotalMoney = TotalMoney + userWins;
}
setText('houseArea', houseHand + 'house total is: ' + houseTotal);
if (21 - userTotal < 21 - houseTotal && userHandValue !== 'bust' && houseHandValue !== 'bust')
setText('userArea', 'Player total is: ' + userTotal + ' Player wins!');
else if (21 - userTotal > 21 - houseTotal && userHandValue !== 'bust' && houseHandValue !== 'bust')
setText('userArea', 'Player total is: ' + userTotal + ' Player loses!');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.