Current Events > Any programmer know how to do this with Javascript? Need some idea

Topic List
Page List: 1
LastTomorrow
12/06/17 2:23:00 PM
#1:


Create a function using JavaScript that calculates the area of a triangle.
*b*h
Validate that the Width and Height are both numbers.
Validate that both he Width and Height are both greater than 0
Validate that neither the Width is more than 2X the Height or the Height is more than 2X the Width.
The function should be called from the onclick event of the Calculate Area button
The result should be stored in the text box at the bottom of the form and the result should be displayed in bold.

Allow the user to enter 5 whole numbers.
Validate that they are all entered and are numbers.

Basically how to connect to other.
---
Waffle waffle waffle
... Copied to Clipboard!
DevsBro
12/06/17 2:30:14 PM
#2:


You can get the contents of the input boxes in a variety of ways. I would just google it. IIRC, you can do document.getElementById(/*id*/).innerHTML.

To verify type, you should use isNaN(parseFloat()).

The rest is pretty simple boolean checks.

Oh, except the onclick part. Just add onclick= as an attribute to your button.

<button id="whatever" onclick=myfunc>Calculate Area</button>
---
... Copied to Clipboard!
Questionmarktarius
12/06/17 2:35:57 PM
#3:


Why do you need five numbers to calculate a triangle?
... Copied to Clipboard!
PoopPotato
12/06/17 2:37:32 PM
#4:


(shuffle
.:cards:.
If black then "fart"
) end
---
... Copied to Clipboard!
LastTomorrow
12/06/17 2:49:48 PM
#5:


Questionmarktarius posted...
Why do you need five numbers to calculate a triangle?

The next thing is getting the maximum and minimum number
---
Waffle waffle waffle
... Copied to Clipboard!
Laserion
12/06/17 2:55:03 PM
#6:


Why this?
Validate that neither the Width is more than 2X the Height or the Height is more than 2X the Width.

---
There is no "would of", "should of" or "could of".
There is "would've", "should've" and "could've".
... Copied to Clipboard!
LastTomorrow
12/06/17 3:07:27 PM
#7:


Do I do this? var area = .5 * width * height?
---
Waffle waffle waffle
... Copied to Clipboard!
luigi13579
12/06/17 3:20:37 PM
#8:


That should work. Try it and see. Get the form to display first then you can gradually add to it and check it works at each stage.
... Copied to Clipboard!
LastTomorrow
12/06/17 6:43:32 PM
#9:


function calculateArea( width, height ) {
var area = .5 * width * height;
return area;

document.getElementById( "calc" ).onclick = function(){
console.log( calculateArea(document.getElementById("width").value, document.getElementById("height").value);
}

How about this?
---
Waffle waffle waffle
... Copied to Clipboard!
Topic List
Page List: 1