Created
December 6, 2011 15:49
-
-
Save msenkpiel/1438649 to your computer and use it in GitHub Desktop.
Soccer Betting Calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = { | |
calculate:function(resultA, resultB, betA, betB) | |
{ | |
console.log('Result: ' + resultA + ':' + resultB + ' Bet: ' + betA + ':' + betB); | |
if(this.testStrike(resultA, resultB, betA, betB)) | |
{ | |
console.log('3 Points'); | |
return; | |
} | |
else | |
{ | |
if(this.testWinner(resultA, resultB, betA, betB)) | |
{ | |
if(this.testDifference(resultA, resultB, betA, betB)) | |
{ | |
console.log('2 Points'); | |
return; | |
} | |
else | |
{ | |
console.log('1 Points'); | |
return; | |
} | |
} | |
else | |
{ | |
console.log('0 Points'); | |
return; | |
} | |
} | |
}, | |
testStrike:function(resultA, resultB, betA, betB) | |
{ | |
var a = false; | |
var b = false; | |
if(resultA == betA) | |
{ | |
a = true; | |
} | |
if(resultB == betB) | |
{ | |
b = true; | |
} | |
if(a && b) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false | |
} | |
}, | |
testWinner:function(resultA, resultB, betA, betB) | |
{ | |
if(this.getWinnerTeam(resultA, resultB) == this.getWinnerTeam(betA, betB)) | |
{ | |
console.log('bet winner is true'); | |
return true; | |
} | |
else | |
{ | |
console.log('bet winner is false'); | |
return false; | |
} | |
}, | |
getWinnerTeam:function(teamA, teamB) | |
{ | |
var winner = (teamA / teamB); | |
if(isNaN(winner)) | |
{ | |
return 'evenOfPoints'; | |
} | |
else | |
{ | |
if(winner > 1) | |
{ | |
return 'A'; | |
} | |
else | |
{ | |
return 'B'; | |
} | |
} | |
}, | |
testDifference:function(resultA, resultB, betA, betB) | |
{ | |
var resultDiff = 0; | |
var betDiff = 0; | |
if(this.getWinnerTeam(resultA, resultB) == 'A') | |
{ | |
resultDiff = (resultA-resultB); | |
betDiff = (betA-betB); | |
} | |
else | |
{ | |
resultDiff = (resultB-resultA); | |
betDiff = (betB-betA); | |
} | |
console.log('resultDiff:', resultDiff, 'betDiff:', betDiff); | |
if(betDiff == resultDiff) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment