»
EnglishFrenchVietnamese

Print - Area Calculator 2 - JavaScriptBank.com

Full version: jsB@nk » Calculation » Math » Area Calculator 2
URL: https://www.javascriptbank.com/area-calculator-2.html

Area Calculator 2 © JavaScriptBank.comPut a calculator code on your page that can tell a visitor the square units of a square, rectangle, parallelogram, or a triangle.

Full version: jsB@nk » Calculation » Math » Area Calculator 2
URL: https://www.javascriptbank.com/area-calculator-2.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Author Matthew d. Krieg (battlebots102001@yahoo.com)<!-- Beginvar formulas = new Array()formulas["square"] = "Math.pow(num_one,2)";formulas["rectangle"] = "num_one * num_two"formulas["parallelg"] = "num_one * num_two";formulas["triangle"] = "num_one * num_two / 2";function getCheckedNum(){var selected;for(var loop=0;loop<window.document.convert.to_which.length;loop++){if(window.document.convert.to_which[loop].checked == true){selected = loop;}}return selected;}function calculate(num_one,num_two){if((isNaN(parseInt(num_one))) || (isNaN(parseInt(num_two)))){alert('You must enter numbers');return;}var selected_index = getCheckedNum();var selected_value =window.document.convert.to_which[selected_index].value;if((selected_value == "square") && (num_one != num_two)){alert('Your square is not square');return;}formula = formulas[selected_value];var answer = eval(formula);alert(answer);}// End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="convert"> Find the area of a:<br> <input type="radio" checked="yes" name="to_which" value="square">square&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> <input type="radio" name="to_which" value="rectangle">rectangle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> <input type="radio" name="to_which" value="parallelg">parallelogram<br> <input type="radio" name="to_which" value="triangle">triangle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> The base is:<input type="text" size="5" name="base">   The height is: <input type="text" size="5" name="height"><br><input type="button" value="calculate" onclick="calculate(window.document.convert.base.value,window.document.convert.height.value);"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->