Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const modeButtons = document.querySelectorAll('.mode-btn');
+ const thirdWay = document.querySelector('.third-way');
+ const calculateBtn = document.querySelector('.calculate-btn');
+ const results = document.querySelector('.results');
+ const stakesList = document.querySelector('.stakes-list');
+ const profitAmount = document.querySelector('.profit-amount');
+ const totalStakeInput = document.getElementById('total-stake');
+ const oddsInputs = document.querySelectorAll('.odds-input');
+
+ let currentMode = '2way';
+
+ modeButtons.forEach(btn => {
+ btn.addEventListener('click', () => {
+ modeButtons.forEach(b => b.classList.remove('active'));
+ btn.classList.add('active');
+ currentMode = btn.dataset.mode;
+ thirdWay.classList.toggle('hidden', currentMode === '2way');
+ results.classList.add('hidden');
+ });
+ });
+
+ calculateBtn.addEventListener('click', () => {
+ const totalStake = parseFloat(totalStakeInput.value);
+ if (!totalStake || totalStake <= 0) {
+ alert('Please enter a valid stake amount');
+ return;
+ }
+
+ const odds = Array.from(oddsInputs)
+ .slice(0, currentMode === '2way' ? 2 : 3)
+ .map(input => parseFloat(input.value))
+ .filter(odd => odd && odd > 1);
+
+ if (odds.length !== (currentMode === '2way' ? 2 : 3)) {
+ alert('Please enter valid odds for all bookmakers');
+ return;
+ }
+
+ const result = calculateArbitrage(odds, totalStake);
+ if (!result.isArbitrage) {
+ alert('No arbitrage opportunity found with these odds');
+ return;
+ }
+
+ displayResults(result);
+ });
+
+ function calculateArbitrage(odds, totalStake) {
+ const impliedProbs = odds.map(odd => 1 / odd);
+ const totalImpliedProb = impliedProbs.reduce((sum, prob) => sum + prob, 0);
+
+ if (totalImpliedProb >= 1) {
+ return { isArbitrage: false };
+ }
+
+ const profit = ((1 - totalImpliedProb) / totalImpliedProb) * totalStake;
+ const stakes = impliedProbs.map(prob =>
+ (prob / totalImpliedProb) * totalStake
+ );
+
+ return {
+ isArbitrage: true,
+ profit,
+ stakes
+ };
+ }
+
+ function displayResults(result) {
+ results.classList.remove('hidden');
+ profitAmount.textContent = `$${result.profit.toFixed(2)}`;
+
+ stakesList.innerHTML = result.stakes
+ .map((stake, index) => `
+
Bookmaker ${index + 1}: $${stake.toFixed(2)}+ `)
+ .join('');
+ }
+ });