ahsen
ahsen

Reputation: 39

Getting value from other function - Javascript

I have html5 score base game. when game over, end screen shows total score via the below function:

this.show = function (a)
{
    b.text = TEXT_GAMEOVER;
    e.text = TEXT_SCORE + ": " + a;
    d.visible = !0;
};

Now i want to get total score that is a or e.text in the onclick button release function:

var a;
this._onButSendRelease = function ()
{ 
       console.log(a);
}

but a is undefined, Please help me how i can do that.

Upvotes: 0

Views: 48

Answers (1)

Zenoo
Zenoo

Reputation: 12880

You can simply store your score in a variable declared in the global scope :

var score; //Declare your variable here

this.show = function (a)
{
    b.text = TEXT_GAMEOVER;
    e.text = TEXT_SCORE + ": " + a;
    score = a; //Populate your variable here
    d.visible = !0;
};

this._onButSendRelease = function ()
{
    console.log(score); //Display your variable here
}

Upvotes: 1

Related Questions