函数调用函数javascript
问题描述:
我正在做一个游戏谁想成为百万富翁,我想显示一个 用户赢得他或者他完成了游戏或给出错误答案的金额。这是错误答案的功能(结束游戏),我不知道如何添加/通话金额代码。从有机磷农药的意见函数调用函数javascript
// Executes the proceedure of guessing incorrectly, losing the game.
self.wrongAnswer = function(elm) {
$("#" + elm).slideUp('slow', function() {
startSound('wrongsound', false);
$("#" + elm).css('background', 'red').slideDown('slow', function() {
$("#game").fadeOut('slow', function() {
$("#game-over").html('Game Over!')
$("#game-over").fadeIn('slow');
self.transitioning = false;
});
});
});
}
// Gets the money formatted string of the current won amount of money.
self.formatMoney = function() {
return self.money().money(0, '.', ',');
}
};
答
最终的解决方案: -
只需添加的地方正确的函数调用您希望它出现。
$('#game-over').html("Game Over!<br \>You would've won " + self.formatMoney());
原因之一,在那里你要插入的钱吗?像'$('#game-over')。html('游戏结束!
你将赢得'+ self.formatMoney')'可能会起作用。 – ShuberFu
你对这段代码有什么问题吗?描述你期望它做什么以及它实际上在做什么。 –
我们也不知道。或者你是否暗示你想调用'formatMoney'函数并在'Game Over !'旁显示结果? – Bergi