Created
March 7, 2011 23:51
-
-
Save chrissharkey/859543 to your computer and use it in GitHub Desktop.
Calculate the age of person you can date based on your net worth
This file contains hidden or 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
<html> | |
<head> | |
<title>Age Dating Calculator</title> | |
<script> | |
<!-- | |
/* This function does the actual calculation as described in your email*/ | |
function calculate(age, worth) { | |
/* If they are less than 14 assume they wouldn't date anyone more than 1 year | |
younger than them. */ | |
if (age <= 16) return age - 1; | |
/* Calculate the percentage reduction off 50% of age and apply it */ | |
var percentage = 0.5 - (Math.log(worth / 1000000) / Math.log(10) + 1) / 10; | |
/* You can't be punished by more than 50% of your age no matter how poor you are */ | |
if (percentage > 0.5) percentage = 0.5; | |
/* Make sure we aren't going below their age */ | |
if (percentage < 0) percentage = 0; | |
/* The actual rule with the new percentage applies percentage * age + 7 */ | |
var minimum_age = percentage * age + 7; | |
/* Make sure no matter how rich they are they can't date children */ | |
if (age > 16 && minimum_age < 16) minimum_age = 16; | |
return Math.ceil(minimum_age); | |
} | |
/* This function takes the data from the form, checks it for sanity | |
and then puts it into the calculate function and puts the result | |
into the result field */ | |
function doCalculation() { | |
var age = parseInt(document.getElementById('age').value); | |
var worth = parseInt(document.getElementById('worth').value); | |
var result = document.getElementById('result'); | |
result.value = ''; | |
if (!age || age <= 0 || age > 200 || !worth || worth <= 0) result.value = 'Invalid input'; | |
else { | |
result.value = calculate(age, worth); | |
} | |
} | |
//--> | |
</script> | |
</head> | |
<body> | |
<h1>Age Dating Calculator</h1> | |
Age: <input id="age" type="text" /><br /> | |
Net Worth: <input id="worth" type="text" /><br /> | |
<input type="button" id="calculate" value="Calculate" onclick="doCalculation()"/><br /> | |
<br /><hr /><br /> | |
Result: <input id="result" type="text" /><br /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment