samedi 29 novembre 2014

When I randomize the bank variable, bankMoney becomes NaN


Pretty self explanitory like my other questions. The problem is that when the person doesn't choose a bank, the variable bankMoney becomes NaN upon the first time calling payDay When they don't choose, its supposed to randomize via my random function, but I don't think it is. could someone please tell me why and/or fix it?


Thanks in advance.


If anymore code is needed ie: a function I missed, missing characters etc., just tell me.


Code snipets needed to understand/fix problem:



function random(high,low) {
return Math.floor((Math.random()*((high + 1) - low)) + low)
}

function propertyIncome() {
bankMoney = bankMoney + houseIncome
}
var job = "Part time"
function round() {
bankMoney = Math.ceil(bankMoney * 100) / 100;
pocketMoney = Math.ceil(pocketMoney * 100) / 100;
}
function intrest() {
if(bankMoney > 0) {
positiveIncome(0)
}
if(bankMoney < 0) {
negativeIncome(0)
}
round()
}
var salary = 10000
var bankMoney = 120000
var bank = prompt("choice a bank. (Put in the number, not the name.) (You only get to do this once, so choose carefully.) \n 1. A&A Positive income: 10% Negative income: 25% \n2. B&C Positice income: 5% Negative income: 7% \n3. Limburgdi International: Positive income: 12.5% negative income: 30% \n4.S&N Positive uncome: 2.5% Negative income: 5%")
if(bank < 1) {
bank = random(1,4)
}
if(bank > 4) {
bank = random(1,4)
}
if(bank == 1) {
function positiveIncome() {
bankMoney = bankMoney + (bankMoney * 0.1)
}
function negativeIncome() {
bankMoney = bankMoney + (bankMoney * 0.25)
}
}
if(bank == 2) {
function positiveIncome() {
bankMoney = bankMoney + (bankMoney * 0.05)
}
function negativeIncome() {
bankMoney = bankMoney + (bankMoney * 0.07)
}
}
if(bank == 3) {
function positiveIncome() {
bankMoney = bankMoney + (bankMoney * 0.125)
}
function negativeIncome () {
bankMoney = bankMoney + (bankMoney * 0.3)
}
}
if(bank == 4) {
function positiveIncome() {
bankMoney = bankMoney + (bankMoney * 0.025)
}
function negativeIncome() {
bankMoney = bankMoney + (bankMoney * 0.05)
}
}
var withdrawl1 = prompt("How much would you like to withdrawl? MUST Be GREATER THAN 1 if not greater than one, it will randomize, and you may not like the outcome. \n(bank transactions are taxed 9%)")
if(withdrawl1 < 1) {
withdrawl1 = Math.floor((Math.random()*(bankMoney - 1)) +1)
}
var pocketMoney = withdrawl1 - withdrawl1 * 0.09
bankMoney = bankMoney - withdrawl1
var randomVariable3 = " Your pocket money is $"
alert("Your new bank balance is $" +bankMoney +"\n" +randomVariable3 +pocketMoney)
function payDay() {
bankMoney = bankMoney + (salary - (salary * 0.05))
intrest()
propertyIncome()
round()
alert("You have been paid,and your bank account has been given intrest. your new bank balance is: $" +bankMoney)
}
var house = prompt("Pick a house. Put in the number, not the name. (property income is 10% with $0 tax. \n1)Mansion: $800,000 \n2)RanchSyle: $250,000 \n3)TwoStory: $300,000 \n4)R.V.: $50,000")
if(house == 1) {
var houseIncome = 80000
bankMoney = bankMoney - 800000
}
if(house == 2) {
var houseIncome = 25000
bankMoney = bankMoney - 250000
}
if(house == 3) {
var houseIncome = 30000
bankMoney = bankMoney - 300000
}
if(house == 4) {
var houseIncome = 5000
bankMoney = bankMoney - 5000
}
function propertyIncome() {
bankMoney = bankMoney + houseIncome
}
payDay()




Aucun commentaire:

Enregistrer un commentaire