Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please can you help

    ......................
    Last edited by jacko1982; 07-05-2006 at 04:53 PM. Reason: ......

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>test</TITLE>

    <
    SCRIPT type="text/javascript"

    var 
    shapeArray = new Array (4);
    var 
    RectangleLength
    var 
    RectangleWidth
    var 
    sum1;
    var 
    sum2;
    var 
    circle;

    function 
    test(){

    for (var  
    i0ishapeArray.lengthi++){

    shape=window.prompt('Please enter shape "r" for rectangle or "c" for Circle'); 

    if(
    shape=='r'){

    RectangleLength window.prompt('Please enter the length of the rectangle in centimetres','');
    RectangleLength=parseFloat(RectangleLength);

    RectangleWidth window.prompt('Please enter the width of the rectangle in centimetres','');
    RectangleWidth=parseFloat(RectangleWidth);

    shapeArray[i]='The area of the '+shape+' is ' +RectangleLength RectangleWidth' square centimetres <br>'

    }

    if (
    shape=='c'){
    circle window.prompt('Please enter the radius in centimetres','');
    circle=parseFloat(circle);

    shapeArray[i]='The radius of the circle is '+circle circle 3.142+'<br>'

    }

    document.getElementById("display").innerHTML+=shapeArray[i]

    }

    }



    </SCRIPT>
    </HEAD>
    <BODY onload="test()">

    <div id="display"></div>

    </BODY>
    </HTML> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    great i will have a go many thanks

  • #4
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks

    ........................................
    Last edited by jacko1982; 07-05-2006 at 04:54 PM. Reason: ...............................

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You could use toFixed(2) for 2 decimal places

    Change this line

    shapeArray[i]='The area of the '+shape+' is ' +RectangleLength * RectangleWidth+ ' square centimetres <br>'

    to

    shapeArray[i]='The area of the '+shape+' is ' +(RectangleLength * RectangleWidth).toFixed(2)+ ' square centimetres <br>'

    and this line

    shapeArray[i]='The radius of the circle is '+circle * circle * 3.142+'<br>'

    to

    shapeArray[i]='The radius of the circle is '+(circle * circle * 3.142).toFixed(2)+'<br>'
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #6
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help

    .......................................................
    Last edited by jacko1982; 07-05-2006 at 04:54 PM.

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    My previous reply does the same thing but if you'd prefer the function then

    Change this line

    shapeArray[i]='The area of the '+shape+' is ' +RectangleLength * RectangleWidth+ ' square centimetres <br>'

    to

    shapeArray[i]='The area of the '+shape+' is ' +roundToTwoPlaces(RectangleLength * RectangleWidth)+ ' square centimetres <br>'

    and this line

    shapeArray[i]='The radius of the circle is '+circle * circle * 3.142+'<br>'

    to

    shapeArray[i]='The radius of the circle is '+roundToTwoPlaces(circle * circle * 3.142)+'<br>'


    and put the new function at the end of the script
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #8
    New to the CF scene
    Join Date
    Jul 2006
    Location
    skipton
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im a lil bit of a newbie here so i was hoping if you guys could help me .is there any way to do this script in both metric and imperial as it wouuld prove usefull to my draugthsmen at my work environment any help in this matter would be fantastic

    My e-mail is alimcvev@hotmail.com

    HTML>
    <HEAD>
    <TITLE>M 150 TMAO3 Question 2 Stuart Randall X4471321 </TITLE>
    <SCRIPT type="text/javascript">
    var shapeArray = new Array (5);
    var RectangleLength;
    var RectangleWidth;
    var sum1;
    var sum2;
    var sum3;
    var circle;
    function test(){
    for (var i= 0; i< shapeArray.length; i++){
    Mesure=window.prompt('Please enter the format of the size ("M" for metric or "I" for imperial)');

    shape=window.prompt('Please enter shape "r" for rectangle or "c" for Circle');
    if(shape=='r'){
    RectangleLength = window.prompt('Please enter the length of the rectangle in centimetres','');
    while(mesure== I * 2.54)
    RectangleLength=parseFloat(RectangleLength);
    RectangleWidth = window.prompt('Please enter the width of the rectangle in centimetres','');
    while(mesure== I * 2.54)
    RectangleWidth=parseFloat(RectangleWidth);
    shapeArray[i]='The area of the '+shape+' is ' +RectangleLength * RectangleWidth+ ' square centimetres <br>'
    }
    while(mesure== I * 2.54)
    if (shape=='c'){
    circle = window.prompt('Please enter the radius','');
    circle=parseFloat(circle);
    shapeArray[i]='The radius of the circle is '+circle * circle * 3.142+'<br>'
    }
    document.getElementById("display").innerHTML+=shapeArray[i]
    }
    }
    document.write('<BR>' + 'Thank you for using this program')
    </SCRIPT>
    </HEAD>
    <BODY onload="test()">
    <div id="display"></div>
    </BODY>
    </HTML>

    Is as far as i have got im not sure on the rest please help im not sure where
    while(mesure== I * 2.54) should go
    Last edited by Alimcvev; 07-19-2006 at 02:05 AM.


  •  

    Posting Permissions

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