javascript - boolean question - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

javascript - boolean question

#1 Midevil Chaos

  • Group: Member
  • Posts: 6
  • Joined: 28-July 12

Posted 28 July 2012 - 07:48 PM

I have a problem of sorts. I am trying to do a mortgage calculator.

within the last pair of parentheses in the second "if" (on the first line of that "if"), i need a greater than statement. It has to state that the value of the down_payment variable cannot be greater than 51% of the property_value variable. I have no idea how to state such a thing using a boolean statement. (Note that all of this will be done DURING the validation phase).


if (property_value.value == "" || isNaN(property_value.value) || (property_value.value <= 60000)){
    property_value.style.border = "red solid 2px";
    valid = false;

}if (down_payment.value == "" || isNaN(down_payment.value) || (){
    down_payment.style.border = "red solid 2px";
    valid = false;}


#2 spike_hacker_inc

  • Group: Member
  • Posts: 1,328
  • Joined: 27-April 05

Posted 29 July 2012 - 03:18 AM

View PostMidevil Chaos, on 28 July 2012 - 07:48 PM, said:

I have a problem of sorts. I am trying to do a mortgage calculator.

within the last pair of parentheses in the second "if" (on the first line of that "if"), i need a greater than statement. It has to state that the value of the down_payment variable cannot be greater than 51% of the property_value variable. I have no idea how to state such a thing using a boolean statement. (Note that all of this will be done DURING the validation phase).


if (property_value.value == "" || isNaN(property_value.value) || (property_value.value <= 60000)){
property_value.style.border = "red solid 2px";
valid = false;

}if (down_payment.value == "" || isNaN(down_payment.value) || (){
down_payment.style.border = "red solid 2px";
valid = false;}

Hey there Midevil,

I hope I am understanding your question correctly, you would like to execute the last "if statement" if the variable down_payment's value is greater than 51%, although I don't understand the relation to property_value... This is assuming that down_payment variable is sorting a type integer from 0 to 100 for the comparison of a percentage.

var dp = down_payment.value;

if (dp > 51 || dp == "" || isNaN(dp)) {
	down_payment.style.border = "red solid 2px";
	valid = false;
}

I hope this is the code you looking for, again this is assuming the down_payment value is between 0 and 100 to make up a percentage. If it is not, you can simply make another variable to store the percentage calculated from which ever variables you use to make up the percentage. The basic comparison operators are:
Equal : ==
Greater Than : >
Less Than : <
Greater/Equal To : >=
Smaller/Equal To : <=

Please let me know if this is what you were looking for and if you require anything else.

Peace Out

#3 Midevil Chaos

  • Group: Member
  • Posts: 6
  • Joined: 28-July 12

Posted 29 July 2012 - 05:12 PM

Hello Spike.


(Sorry if I hadn't put my code into quotation - I was using "noscript". I have added the code in code quotations for reference).


Let's say that you want to buy a house worth 500,000$, the down payment that you would make could not be greater than 50% of the property value (500,000$). This means that you could not spend more than 250,000$, while anything from 51%-100% could not be accepted.

In other words, your down payment (let's say 250,000$) is based on the property value of 500,000$. Therefore, the 250,000$ down payment is based on the property value.

This is what I do not understand how to do. Since this is 2 variables which I have to incorporate within a single statement - unless there is another way that I do not know about.

#4 spike_hacker_inc

  • Group: Member
  • Posts: 1,328
  • Joined: 27-April 05

Posted 30 July 2012 - 12:57 AM

Hey again Midevil,

:) That makes alot more sense now, sorry It probably made sense before your explaining it a second time but I'm slow like that Posted Image...

if (down_payment.value >= (property_value.value * 0.50) || dp == "" || isNaN(dp)) {
        down_payment.style.border = "red solid 2px";
        valid = false;
}

I think you'll find the revised code alot more useful, let me know if this is what you were looking for... Remember you can put in multiple statements with in an if statement as long as it returns a Boolean value. Hope this helped...

Peace Out Posted Image

#5 Midevil Chaos

  • Group: Member
  • Posts: 6
  • Joined: 28-July 12

Posted 31 July 2012 - 12:27 PM

Thanks spike :)

I will post the whole coding I have. I know there are thing I don't understand, but I am keen in understanding my mistakes and the howtos to do them :)

I will create a new thread with my current project. Maybe you (and/or others) could take a look at it at the top js, where I have included the problems I've been having.

Share this topic: