Create a webpage that will ask the user for a radius.
That number will be use to find the area of a circle with that radius, and then continue to calculate the next 9 circles with radii incrementing by one unit each time, and display the results to the page.
Then create a conditional statement that will limit the output to only even numbered radii.
Then a conditional statement that will limit the output to only radii divisible by 3.
And I have a code so far that looks like this:
<html>
<body>
<center>
Radius:<input type="text" name="radius" value=1><br>
<button type="button" onClick="calculate(radius.value)"> Get Next </button><br>
</center>
<script>
function calculate(rad)
{
for(var counter=0;counter<10;counter++)
{
if((rad+counter)%2==0)
{
if((rad+counter)%3==0)
{
var pie = 3.14;
document.write("(" + rad + "+" + counter + ")" + "*" + "(" + rad + "+" + counter + ")" + "*" + pie + "=");
var area = ((parseInt(rad)+counter)*(parseFloat(rad)+counter))*(pie);
document.write(area + "<br>");
}
}
}
}
</script>
</body>
</html>
So far it's not working. I'm new to scripting, and I'm having trouble understanding what's wrong.
Hoping someone could help out.
Thanks.
10-23-2012, 11:11 AM
007Julien
Do not use document.write which is made to write on the page during is opening but never when the document is closed (after the click, in your case).
Insert a div with, for example, an id="rsp" and replace your document.write by a
document.getElementById('rsp').innerHTML='<p>'+area+'</p>';
NB : See this page The <center> element is deprecated in HTML 4.01. Pi is given by Math.PI. Take care with radius.value and rad which are strings (counter+parseInt(rad) would be better)...