»
AnglaisFran�aisVietnamien

Imprimer - Domaine Calculatrice 2 - JavaScriptBank.com

Version compl�te: jsB@nk » Calcul » Math » Domaine Calculatrice 2
URL: https://www.javascriptbank.com/area-calculator-2.html

Domaine Calculatrice 2 © JavaScriptBank.comMettez un Calculateur de code sur votre page qui permet d'indiquer à un visiteur de la place des unités d'un carré, rectangle, parallélogramme, ou un triangle.

Version compl�te: jsB@nk » Calcul » Math » Domaine Calculatrice 2
URL: https://www.javascriptbank.com/area-calculator-2.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Author Matthew d. Krieg ([email protected])<!-- 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-->