Skip to content

Instantly share code, notes, and snippets.

@camh96
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save camh96/3317bde677c1086840fc to your computer and use it in GitHub Desktop.

Select an option

Save camh96/3317bde677c1086840fc to your computer and use it in GitHub Desktop.
Calculate shares
function insuffFunds() {
var txt;
var r = confirm("You probably don't have enough to purchase the miniumum amount, continue?");
if (r == true) {
alert("NOPE");
} }
function sharebuy(){
cash = prompt('How much money do you have?') // get cash amount
share = prompt('How much do shares cost?') //get share cost
// company = prompt('what is the company name?') // get company name (removed for now)
sharepurchase = Math.floor (cash/share) // Math.floor to round down i.e you can't buy 10.6 shares
wise = Math.floor (sharepurchase/12)
//divide cash by share cost to get amount of shares one can buy
// store variable to be used later
}
if (sharepurchase > 100){
alert('You should buy a max of ' + wise + ' shares, but the limit is ' + sharepurchase)
}// tells us what we can buy
else {
insuffFunds();
} // Warns user that they may not have enough for the purchase, and asks if they wish to continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment