Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

javascript - boolean question


  • Please log in to reply

#1
Midevil Chaos

Midevil Chaos

    New Member

  • Member
  • Pip
  • 6 posts
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;}

Edited by Midevil Chaos, 29 July 2012 - 05:13 PM.

  • 0

Advertisements


#2
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts

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
  • 0

#3
Midevil Chaos

Midevil Chaos

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
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.

Edited by Midevil Chaos, 29 July 2012 - 05:15 PM.

  • 0

#4
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts
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
  • 0

#5
Midevil Chaos

Midevil Chaos

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
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.
  • 0






Similar Topics

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP