Open hermesos opened 4 months ago
Match Result Odds:
MS 1: undefined - Bet Amount: undefined MS X: undefined - Bet Amount: undefined MS 2: undefined - Bet Amount: undefined Double Chance Odds:
ÇŞ 1-X: undefined - Bet Amount: undefined ÇŞ 1-2: undefined - Bet Amount: undefined ÇŞ X-2: undefined - Bet Amount: undefined Total Bet Amount: 120
Total Possible Winnings: 0
// Get elements const matchResultOdds = document.querySelectorAll('.match-result-odd'); const doubleChanceOdds = document.querySelectorAll('.double-chance-odd'); const totalBetAmount = document.getElementById('total-bet-amount'); const calculateButton = document.getElementById('calculate-button'); const resultArea = document.getElementById('result-area');
// Initialize variables let matchResultOddsArray = []; let doubleChanceOddsArray = []; let totalOdds = 0; const minimumBetAmount = 20;
// Event listener for calculate button calculateButton.addEventListener('click', () => { // Get match result odds and convert them to numbers matchResultOddsArray = Array.from(matchResultOdds).map(odd => Number(odd.value));
// Get double chance odds and convert them to numbers doubleChanceOddsArray = Array.from(doubleChanceOdds).map(odd => Number(odd.value));
// Calculate total odds if (matchResultOddsArray.length > 0 && doubleChanceOddsArray.length > 0) { totalOdds = matchResultOddsArray.reduce((a, b) => a + b, 0) + doubleChanceOddsArray.reduce((a, b) => a + b, 0); }
// Get total bet amount const totalBetAmountValue = Number(totalBetAmount.value);
// Check if total bet amount is valid if (totalBetAmountValue < minimumBetAmount 6) { alert('Total bet amount must be at least ' + minimumBetAmount 6); return; }
// Calculate bet amounts const betAmounts = calculateBetAmounts(matchResultOddsArray, doubleChanceOddsArray, totalBetAmountValue);
// Display results resultArea.innerHTML = `
Match Result Odds:
`; });
// Function to calculate bet amounts function calculateBetAmounts(matchResultOdds, doubleChanceOdds, totalBetAmount) { // Calculate the total amount that can be distributed to all betting options const distributableAmount = totalBetAmount - (matchResultOdds.length + doubleChanceOdds.length) * minimumBetAmount;
// Calculate the minimum bet amounts for each betting option const minimumBetAmounts = matchResultOdds.map( => minimumBetAmount).concat(doubleChanceOdds.map( => minimumBetAmount));
// Calculate the remaining amount after distributing the minimum bet amounts const remainingAmount = distributableAmount - minimumBetAmounts.reduce((a, b) => a + b, 0);
// Calculate the maximum bet amounts for each betting option const maximumBetAmounts = matchResultOdds.map((odd, index) => Math.floor(remainingAmount / matchResultOdds.length)).concat(doubleChanceOdds.map((odd, index) => Math.floor(remainingAmount / doubleChanceOdds.length)));
// Calculate the best bet amount for each betting option const bestBetAmounts = minimumBetAmounts.map((min, index) => { // Check if the betting option has a maximum bet amount if (maximumBetAmounts[index] > min) { // Calculate the best bet amount by taking the average of the minimum and maximum bet amounts return Math.round((min + maximumBetAmounts[index]) / 2); } else { // Return the minimum bet amount if there is no maximum bet amount return min; } });
// Return the bet amounts return bestBetAmounts; }
// Function to calculate total winnings function calculateTotalWinnings(betAmounts, matchResultOdds, doubleChanceOdds) { // Calculate the total winnings for each betting option const winnings = betAmounts.map((betAmount, index) => { if (index < 3) { return betAmount matchResultOdds[index]; } else { return betAmount doubleChanceOdds[index - 3]; } });
// Return the total winnings return winnings.reduce((a, b) => a + b, 0); }