## Can you show me how to validate height and width are greater than 0

• Topic Archived
1. Boards
2. Game Design and Programming
3. Can you show me how to validate height and width are greater than 0

#### User Info: LastTomorrow

LastTomorrow
8 months ago#1
<form name="Theform" id="frmcontact" method="get">
Enter the width and height of your triangle to calculate the area<br>
Width (b):<input type="text" id="width" name="txtwidth">
Height (h):<input type="text" id="height" name="txtheight">
<input type="button" value="Calculate area" id="calc" onclick="area()">
</form>

</div>

</div>

<hr>

<div id="Five">
<form name="secform" method="get">
<label for="area">The area is:</label>
<input type="text" id="solve" name="area"><br>
</form>

function area() {
var width = Theform.txtwidth.value;
var height = Theform.txtheight.value;
var area = .5 * width * height;
secform.area.value = area;
if (height < 0 && width < 0){
document.getElementById("solve").innerHTML = NaN;
}
if (height < 2 * width && width < 2 * height) {
document.getElementById("solve").innerHTML = NaN;
}
}

Trying to get NAN if I put a negative number in there.
Waffle waffle waffle

#### User Info: nesis

nesis
8 months ago#2
You're close! You'll want to doublecheck which logical operator you need to use in your if statements, in order for execution to go inside them.

Currently, you're using &&, the "AND" logical operator, which takes the form of A && B. For that logical operator to evaluate to true, both A and B must be true. So in your code, if A is less than 0, but B is not less than 0, the if statement's body won't execute. Similarly, if B is less than 0, but A is not less that 0, the if statement's body won't execute. Look at the logical operators in that page, and see which one suits your needs instead of && :)
|__ I make indie games! Get them for free at http://nesis.itch.io __|
|__ Let me know what you think! __________________________|

#### User Info: Cheezmeister

Cheezmeister
8 months ago#3
I make games!
http://luchenlabs.com
1. Boards
2. Game Design and Programming
3. Can you show me how to validate height and width are greater than 0

## Report Message

### Etiquette Issues:

Notes (optional; required for "Other"):
Add user to Ignore List after reporting

## Topic Sticky

You are not allowed to request a sticky.

## Update Topic Flair

You are not allowed to update this topic's flair.

• Topic Archived