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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    question about writing a java script

    hey guys "

    I have question about writing a java script code equivalent to the following figure :




    I've written the code like this ,


    <html>
    <body>

    <script type="text/javascript">
    var x;

    x = 12;

    while (x != 0)
    {
    document.write(" x = " + x +"<BR>");
    x = x - 3;

    }
    document.write("DONE");

    </script>

    </body>
    </html>


    is my answer right or wrong ?? <

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,550
    Thanks
    89
    Thanked 4,936 Times in 4,897 Posts
    Looks fine to me.

    Now what about if the first instruction was "set number to 13".

    What is then wrong with the flow chart? What is then wrong with the code?

    Oh...one VERY minor point.

    You *CAN* write
    Code:
         x = x - 3;
    as
    Code:
         x =- 3;
    Don't change your code. Just FYI.

    Hmmm....*technically* you are doing too much.

    The instruction says "write out the value of the number...".

    You are writing "x =" in addition to that. <grin/>
    Be yourself. No one else is as qualified.

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    4,074
    Thanks
    14
    Thanked 428 Times in 424 Posts
    Quote Originally Posted by Old Pedant View Post
    Code:
         x =- 3;
    Code:
    x -= 3;
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Looks fine to me.

    Now what about if the first instruction was "set number to 13".

    What is then wrong with the flow chart? What is then wrong with the code?

    Oh...one VERY minor point.

    You *CAN* write
    Code:
         x = x - 3;
    as
    Code:
         x =- 3;
    Don't change your code. Just FYI.

    Hmmm....*technically* you are doing too much.

    The instruction says "write out the value of the number...".

    You are writing "x =" in addition to that. <grin/>

    thanks man ,
    I am going to practice more on the question.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,550
    Thanks
    89
    Thanked 4,936 Times in 4,897 Posts
    Quote Originally Posted by Dormilich View Post
    Code:
    x -= 3;
    Dyslexia strikes again.

    (Actually, it's just that my fingers get ahead of my vision/brain at times. I so often type "hte" and "thsi" that it's scary. And as I was typing this I tried to put in "tyep"...sigh.)
    Be yourself. No one else is as qualified.


  •  

    Posting Permissions

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