<h1>Calculate your chances of getting something, by trying to roll the same number (enter probability below)</h1>
<small>for example if you want number <strong>1</strong> out of <strong>2000</strong> possible numbers, and you try to roll <strong>300</strong> times</small>
<form>
<label for="calc">Odds: </label><input type="text" name="calc" id="calc" placeholder="f.e 1/2000">
<label for="rols">Rolls: </label><input type="text" name="rols" id="rols" placeholder="300">
<br>
<button>Calculate</button>
</form>
<div id="result"></div>
var calc, result, form, rols;
var returnSingleElement = function(selector) {
return document.querySelector(selector);
}
calc = returnSingleElement('#calc');
rols = returnSingleElement('#rols');
result = returnSingleElement('#result');
form = returnSingleElement('form');
form.addEventListener('submit', function(e) {
e.preventDefault();
e.stopPropagation();
var d, f, E, r, i, s, R, m;
i = calc.value;
s = i.split('/');
d = parseInt(s[0]);
f = parseInt(s[1]);
R = parseInt(rols.value);
r = 1 - Math.pow( (f - d) / f , R);
console.log('Result', r + '%');
result.innerHTML = (r * 100).toFixed(2) + '% is the chance that you should have recived a winning roll!';
return false;
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.