var g_lives = 3; // our function function isAlive() { if (g_lives <= 0) { return false; } return true; } /* do some stuff in the game then check if the player is alive. */ if (isAlive() == false) { game_end(); }