Build Daily Bonus Ladder Feature for Your Platform [Step-by-Step Process]

Updated on

At EnactOn, we love adding fun features that make our client’s user experience more exciting! One of the newest additions is the Daily Bonus Ladder like freecash, where you can win extra coins daily by climbing a risk-reward ladder.

Daily Bonus Ladder

But how did we develop Daily Bonus Ladder feature, and what goes on behind the scenes? Let’s break it down in a simple, easy-to-understand way, so you can see the magic that powers it.

What is the Daily Bonus Ladder?

The Daily Bonus Ladder is a game of chance that rewards you with coins every day. Here’s how it works:

  • You start with a base reward (for example, 100 coins).
  • You can claim the reward right away or take a risk and try to double it.
  • If you decide to risk it and win, your reward doubles. But if you lose, you lose everything for the day.

What makes the game even more fun is that the chances of doubling the reward get harder the further you go up the ladder. It’s a balance between how much you’re willing to risk for bigger rewards!

How We Built Daily Bonus Ladder Feature – The Tech Behind the Game

Now, let’s talk about the technical side. While it sounds like magic, we used some simple math and coding to make this feature work!

Step by Step Algorithm For the Bonus Ladder

Let’s break down how we built the bonus ladder step by step:

  1. Start with a Base Reward: Every day, you start with a fixed amount of coins, like 100 coins.
  2. Doubling the Reward: If you decide to risk your coins, you have a chance to double them. For example, if you start with 100 coins and win, you now have 200 coins.
  3. Decreasing Chances: The more you win, the harder it gets to double your reward again. Here’s how:
    • On your first attempt, you have a high chance of doubling (90% chance).
    • On your second attempt, the chance of success goes down to 80%.
    • On your third attempt, the chance drops to 70%, and so on.
  4. So, as you climb the ladder, the risk increases. Will you keep going, or will you take the safe route and cash out?
  5. Risk vs. Reward: Each time you win, you can either claim your reward or risk it for a chance to double again. If you lose, you lose everything for that day, so it’s all about deciding how far to push your luck.

How the Probability Works

The chances of doubling your reward decrease with each level. We started with a 90% chance on the first level, and then reduced it by 10% at each level, so:

  • Level 1: 90% chance to double.
  • Level 2: 80% chance to double.
  • Level 3: 70% chance to double.
  • And so on…

This makes it harder to keep winning as you climb the ladder.

How to Create the Daily Bonus Ladder

For those curious about the technical side, here’s a simple JavaScript code snippet we used to power the ladder feature:

// Function to calculate the probability of winning at each ladder level
function getWinningProbability(level) {
    // Start with a high probability of 90% and decrease by 10% with each level
    return Math.max(90 - (level * 10), 10);  // Ensure it doesn't go below 10%
}

// Function to simulate a daily bonus ladder
function dailyBonusLadder(baseReward, maxLevels) {
    let currentReward = baseReward;   // Start with the base reward
    let currentLevel = 1;             // Start at the first level

    while (currentLevel <= maxLevels) {
        const chanceToWin = getWinningProbability(currentLevel); // Get current winning chance

        console.log(`Level ${currentLevel}: ${chanceToWin}% chance to win. Current reward: ${currentReward} coins.`);

        // Generate a random number between 1 and 100 to determine the outcome
        const randomOutcome = Math.random() * 100;

        if (randomOutcome <= chanceToWin) {
            // User wins this level, double the reward
            currentReward *= 2;
            console.log(`You won! Your reward is now ${currentReward} coins.`);
        } else {
            // User loses, exit the ladder with nothing for this round
            console.log('You lost! You forfeit your reward for today.');
            currentReward = 0;
            break;
        }

        // Ask user if they want to continue to the next level or claim their reward
        const continuePlaying = confirm('Do you want to risk and go to the next level?');

        if (!continuePlaying) {
            console.log(`You claimed your reward of ${currentReward} coins!`);
            break;
        }

        currentLevel++;  // Move to the next level
    }

    // Return the final reward (could be 0 if they lost)
    return currentReward;
}

// Example usage of the function
const baseReward = 100;      // Starting reward is 100 coins
const maxLevels = 5;         // Let's say the maximum ladder level is 5

// Start the game
const finalReward = dailyBonusLadder(baseReward, maxLevels);

console.log(`Final reward after playing: ${finalReward} coins.`);

Let’s break down the code to develop Daily Bonus Ladder feature step by step in simple terms. This explanation will help you understand how the code works without diving too deep into technical jargon.

1. getWinningProbability(level)

function getWinningProbability(level) {
    return Math.max(90 - (level * 10), 10);  // Ensure it doesn't go below 10%
}

What This Does:

  • Purpose: This function calculates the chance of winning at each level of the ladder.
  • Explanation:
    • The function starts with a 90% chance of winning on the first level.
    • For each higher level, it reduces the chance by 10%.
    • For example, at level 1, it’s 90%, at level 2, it’s 80%, and so on.
    • The function makes sure the probability never goes below 10% (even at the highest levels) by using Math.max(), which ensures a minimum value of 10.

Example:

  • At level 1, the chance is 90%.
  • At level 2, the chance is 80%.
  • At level 3, the chance is 70%.
  • If you reach a high level like level 9, the chance would only be 10%.

2. dailyBonusLadder(baseReward, maxLevels)

This is the main function that runs the Daily Bonus Ladder game.

function dailyBonusLadder(baseReward, maxLevels) {
    let currentReward = baseReward;  // Start with the base reward
    let currentLevel = 1;            // Start at the first level



What This Does:

  • Purpose: This function simulates the entire ladder game, where users can claim or gamble their reward.
  • Explanation:
    • baseReward: The starting reward, such as 100 coins.
    • maxLevels: The maximum number of levels the user can climb, for example, 5 levels.
    • currentReward: This variable stores the user’s current reward, which starts with the baseReward.
    • currentLevel: Tracks the level the user is on, starting from level 1.

3. Calculating the Chance to Win

while (currentLevel <= maxLevels) {
    const chanceToWin = getWinningProbability(currentLevel); // Get current winning chance
    console.log(`Level ${currentLevel}: ${chanceToWin}% chance to win. Current reward: ${currentReward} coins.`);
    

What This Does:

  • Purpose: This part checks the user’s chance of winning at each level.
  • Explanation:
    • The code runs a loop that continues while the user is climbing levels.
    • At each level, it calls the getWinningProbability function to determine the chance of winning.
    • The console.log() line just prints the current level, chance, and reward for debugging purposes.

4. Random Chance Calculation

const randomOutcome = Math.random() * 100;

if (randomOutcome <= chanceToWin) {
    currentReward *= 2;
    console.log(`You won! Your reward is now ${currentReward} coins.`);
} else {
    console.log('You lost! You forfeit your reward for today.');
    currentReward = 0;
    break;
}

What This Does:

  • Purpose: This is where the actual gamble happens.
  • Explanation:
    • Math.random() generates a random number between 0 and 100.
    • If the random number is less than or equal to the chance of winning (chanceToWin), the user wins, and their reward is doubled.
    • If the random number is greater, the user loses and forfeits the reward for the day. The currentReward is set to 0, and the game ends with the break statement.

Example:

  • If the user is at level 1 with a 90% chance of winning, and the random number is 65, they win and double their reward.
  • If the random number is 95, they lose and get nothing for that day.

5. Asking the User to Continue or Stop

const continuePlaying = confirm('Do you want to risk and go to the next level?');

if (!continuePlaying) {
    console.log(`You claimed your reward of ${currentReward} coins!`);
    break;
}

currentLevel++;  // Move to the next level
}

What This Does:

  • Purpose: This part lets the user decide if they want to continue gambling or claim their reward.
  • Explanation:
    • confirm() shows a pop-up message asking the user if they want to continue or claim their reward.
    • If the user chooses to stop, the game ends, and they claim their current reward.
    • If the user chooses to continue, they move to the next level (the code increases currentLevel by 1), and the game continues

6. Returning the Final Reward

return currentReward;

What This Does:

  • Purpose: After the game ends (either by winning, losing, or claiming), this part returns the final reward.
  • Explanation: Whether the user lost all their coins or stopped at some point to claim their reward, this line sends back the final result of the game.

7. Example Usage

const baseReward = 100;      // Starting reward is 100 coins
const maxLevels = 5;         // Let's say the maximum ladder level is 5

const finalReward = dailyBonusLadder(baseReward, maxLevels);
console.log(`Final reward after playing: ${finalReward} coins.`);

What This Does:

  • Purpose: This is an example of how the function can be used on a website.
  • Explanation:
    • We set the base reward to 100 coins and the maximum levels to 5.
    • Then we run the dailyBonusLadder() function to simulate the game.
    • The final reward (whether 0 or higher) is printed to the console with console.log().

Summary of How the Code Works:

  1. Starts with a base reward, such as 100 coins.
  2. At each level, the user has a decreasing chance to win and double their reward.
  3. If they win, they can choose to continue or claim their reward.
  4. If they lose, they lose everything for that day.
  5. The code ensures that the risk increases the further they go up the ladder, making it a fun and strategic game.

Conclusion

With this code, we’ve created a fun, simple game that adds excitement and risk to your users’ experience on the website. Each level makes it harder to win, but the reward doubles, making users weigh their choices carefully. If they stop at the right time, they walk away with a nice bonus. If they get too greedy, they might lose everything!