Results 1 to 2 of 2

Thread: beginner help with code

  1. #1
    Join Date
    Oct 2012

    beginner help with code

    I have an assigment as follows:

    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:

    Radius:<input type="text" name="radius" value=1><br>
    <button type="button" onClick="calculate(radius.value)"> Get Next </button><br>
    function calculate(rad)
    for(var counter=0;counter<10;counter++)
    var pie = 3.14;
    document.write("(" + rad + "+" + counter + ")" + "*" + "(" + rad + "+" + counter + ")" + "*" + pie + "=");
    var area = ((parseInt(rad)+counter)*(parseFloat(rad)+counter))*(pie);
    document.write(area + "<br>");

    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.


  2. #2
    Join Date
    Oct 2010
    Versailles, France
    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

    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)...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center