I have created this simple straight bet calculator using JavaScript.
It allows me to calculate, if it is a winning ticket, how much the payout will be.
How it works?
First I will enter the moneyLine number, which can be mostly any 3 digits number and I then enter the bet amount.
Now, the moneyLine can either be negative (-) if betting a favorite or positive (+) if betting the underdog.
Please see the code below:
For testing proposes, I use any -110 or 110 and then, any bet amount. But it can actually be any chosen moneyLine and betAmount.
// Single Straight Sports Bet Calculator
function betCalculator(moneyLine) {
var odds;
var betAmount = +prompt("Enter Bet Amount");
if (moneyLine >= 0) {
odds = moneyLine >= 0 ? (moneyLine / 100) + 1 : (100 / Math.abs(moneyLine)) + 1;
} else {
odds = moneyLine >= 0 ? (moneyLine / 100) + 1 : (100 / Math.abs(moneyLine)) + 1;
} return ((odds * betAmount).toFixed(2));
}
alert(betCalculator(+prompt("Enter Money Line")));
// Single Straight Sports Bet Calculator
function betCalculator(moneyLine) {
var odds;
var betAmount = +prompt("Enter Bet Amount");
if (moneyLine >= 0) {
odds = moneyLine >= 0 ? (moneyLine / 100) + 1 : (100 / Math.abs(moneyLine)) + 1;
} else {
odds = moneyLine >= 0 ? (moneyLine / 100) + 1 : (100 / Math.abs(moneyLine)) + 1;
} return ((odds * betAmount).toFixed(2));
}
alert(betCalculator(+prompt("Enter Money Line")));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…