2016-05-23 173 views
0

我正在做一個遊戲誰想成爲百萬富翁,我想顯示一個 用戶贏得他或者他完成了遊戲或給出錯誤答案的金額。這是錯誤答案的功能(結束遊戲),我不知道如何添加/通話金額代碼。從有機磷農藥的意見函數調用函數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, '.', ','); 
    } 
}; 
+1

原因之一,在那裏你要插入的錢嗎?像'$('#game-over')。html('遊戲結束!
你將贏得'+ self.formatMoney')'可能會起作用。 – ShuberFu

+0

你對這段代碼有什麼問題嗎?描述你期望它做什麼以及它實際上在做什麼。 –

+0

我們也不知道。或者你是否暗示你想調用'formatMoney'函數並在'Game Over !'旁顯示結果? – Bergi

回答

1

最終的解決方案: -

只需添加的地方正確的函數調用您希望它出現。

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