函数变成函数调用 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, '.', ',');
    }
};

OPs 注释的最终解决方案: -

只需在您希望它出现的位置添加正确的函数调用即可。

$('#game-over').html("Game Over!<br >You would've won " + self.formatMoney());

最新更新