+ Reply to Thread
Results 1 to 7 of 7

Thread: TAFE STUDENT - what other ways can I write this code?

  1. #1
    goldy30's Avatar
    goldy30 is offline x10Hosting Member goldy30 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    60

    Question TAFE STUDENT - what other ways can I write this code?

    The exercise I done for Javascript was pretty simple but I'm not sure that I've achieved the result the way I was suppose to. The question was just create an application where it gets two numbers and displays the larger number... I done this but I'm wondering what other ways is there to achieve this??

    My code
    HTML Code:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    
    <script type="text/javascript">
    
    function calc()
    {
    var n1 = (document.form1.n1.value);
    var n2 = (document.form1.n2.value);
    
    if    (n1 > n2)
    {
    document.write (n1);
    }
    else
    {
    document.write (n2);
    }
    }
    
    </script>
    
    </HEAD>
    
    <BODY bgcolor="ededed">
    <center>
    
    <h1>Largest Number</h1>
    
    <form name="form1">
    &nbsp;
    1st <input name="n1" size="3">
    &nbsp;
    2nd <input name="n2" size="3">
    &nbsp;
    <input type="button" value="Show" onClick="calc()"><p>
    
    </form>
    </center>
    </BODY>
    </HTML>

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: TAFE STUDENT - what other ways can I write this code?

    The joy of programming is that as long as it works, you've done it right ;)

    From an engineers perspective, can you remove anything and still maintaing functionality?
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  3. #3
    goldy30's Avatar
    goldy30 is offline x10Hosting Member goldy30 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    60

    Re: TAFE STUDENT - what other ways can I write this code?

    Quote Originally Posted by xmakina View Post
    The joy of programming is that as long as it works, you've done it right ;)

    From an engineers perspective, can you remove anything and still maintaing functionality?
    Fair enough.

  4. #4
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: TAFE STUDENT - what other ways can I write this code?

    there's also a version for a pure javascript.
    HTML Code:
    <html>
      <body>
        <script>
          x = prompt("enter a number ");
          y = prompt("Enter another number");
          z=(x>y?x:y);
         alert("the larger number is " + z+ "?");
        </script>
      </body>
    </html>
    the thing here is it runs one time only. there is a way to repeat the stuff so you can play with the code if you want.
    Last edited by dickey; 10-09-2008 at 11:27 PM. Reason: forgot to enclose in html tags.

  5. #5
    goldy30's Avatar
    goldy30 is offline x10Hosting Member goldy30 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    60

    Re: TAFE STUDENT - what other ways can I write this code?

    Quote Originally Posted by dickey View Post
    there's also a version for a pure javascript.
    HTML Code:
    <html>
      <body>
        <script>
          x = prompt("enter a number ");
          y = prompt("Enter another number");
          z=(x>y?x:y);
         alert("the larger number is " + z+ "?");
        </script>
      </body>
    </html>
    the thing here is it runs one time only. there is a way to repeat the stuff so you can play with the code if you want.
    that's cool and all but how do I use that in a form or what such?

  6. #6
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: TAFE STUDENT - what other ways can I write this code?

    You don't*. As your task was simply to "get two numbers and display the larger number" there's no need for forms.

    This is a wonderful example of how important project / job specifications are. You're never asked to store or present the two numbers after the initial display so you don't. Would certainly make a fun debate with your lecturer (if they're there to do more than walk you through the curriculum, that is :P)


    *I'm sure you can, but that's not the point I'm making here.
    Last edited by xmakina; 10-10-2008 at 10:11 AM.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  7. #7
    goldy300's Avatar
    goldy300 is offline x10Hosting Member goldy300 is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    33

    Re: TAFE STUDENT - what other ways can I write this code?

    Quote Originally Posted by xmakina View Post
    You don't*. As your task was simply to "get two numbers and display the larger number" there's no need for forms.

    This is a wonderful example of how important project / job specifications are. You're never asked to store or present the two numbers after the initial display so you don't. Would certainly make a fun debate with your lecturer (if they're there to do more than walk you through the curriculum, that is :P)


    *I'm sure you can, but that's not the point I'm making here.
    No worries then... thanks for the variation.

+ Reply to Thread

Similar Threads

  1. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  2. Student - tafe designs
    By goldy300 in forum Review My Site
    Replies: 4
    Last Post: 10-11-2008, 06:46 PM
  3. TAFE STUDENT - PHP - Send mail - Verify feilds
    By goldy30 in forum Programming Help
    Replies: 7
    Last Post: 10-04-2008, 04:27 PM
  4. Tafe Student
    By goldy30 in forum Review My Site
    Replies: 4
    Last Post: 10-01-2008, 01:27 AM
  5. BB Code Guide
    By Jober68 in forum Tutorials
    Replies: 1
    Last Post: 01-10-2008, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers