JavaScript Tutorial/Language Basics/Expressions
Use parenthesis in expression
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
var inpRadius;
inpRadius = 3;
document.write(Math.PI * ((inpRadius)*(inpRadius)));
// -->
</script>
</head>
<body>
</body>
</html>
Use parenthesis in expression 2
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
function calcArea()
{
inpRadius = 3;
document.write(Math.PI * ((inpRadius)*(inpRadius)));
}
function calcPeri()
{
inpRadius = 3;
document.write(2 * Math.PI * (inpRadius));
}
function calcVol()
{
inpRadius = 3;
document.write(Math.PI * ((inpRadius)*(inpRadius)*(inpRadius)) * (4/3));
}
// -->
</script>
</head>
<body>
<h1>All about Circles and Spheres!</h1>
<P>Click <input type="button" value="HERE" onclick="calcArea();"> to calculate circle area!</p>
<br>
<P>Click <input type="button" value="HERE" onclick="calcPeri();"> to calculate circle perimeter!</p>
<br>
<P>Click <input type="button" value="HERE" onclick="calcVol();"> to calculate sphere volume!</p>
</body>
</html>