Assignment on Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nchgoguy
    New Member
    • Nov 2007
    • 1

    Assignment on Javascript

    This is homework due soon, and I am lost. Due in a few hours. I'm stuck, and looking for how to do this. Any suggestions?

    This time the numbers that you are converting range from zero to one-hundred thousand.
    ...[snipped]
    As with Project 7, you are to write an HTML page, complete with a header, title and a body containing a JavaScript script. The general page describes the behavior of the script. The script first prompts the user for an integer number between 0 and 100,000. Next, the script checks that the user entered a number within the specified range and generated the English name for that number. For instance, if the user entered the number "67,231", the script would generate the name "sixty-seven thousand two hundred and thirty-one". The generated name is inserted in the page, toward the bottom, with an appropriate explanation.

    [snipped]
    Last edited by acoder; Nov 22 '07, 10:53 AM. Reason: snipped parts
  • Death Slaught
    Top Contributor
    • Aug 2007
    • 1137

    #2
    Sorry we are not aloud to help you on homework assignments, please refer to the Posting Guidelines .

    Thanks, Death

    Comment

    • Logician
      New Member
      • Feb 2007
      • 210

      #3
      Originally posted by Death Slaught
      Sorry we are not aloud to help you on homework assignments.
      Is it O.K. to help people quietly?

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        Here is one for Roman numerals. Just rearrange it a bit for your homework.
        :
        [CODE=javascript]function check_romandec( ){
        String.prototyp e.fromRoman= function(){
        var num= '', sum= 0, tem;
        var rGA= [['DCCCC','CM'],['LXXXX','XC'],['VIIII','IX'],['CCCC','CD'],['XXXX','XL'],['IIII','IV']];
        if(/\D/.test(this)==fa lse){
        num= Number(this).to Roman();
        for(var i= 0; i<6; i++) num= num.replace(rGA[i][0],rGA[i][1]);
        return num;
        }
        else{
        var rX= / [^IVXLCDM]/;
        num= this.toUpperCas e();
        if(rX.test(num) ) return '';
        for(var i= 0;i<6;i++)num= num.replace(rGA[i][1],rGA[i][0]);
        var rN= {I:1, V:5, X:10, L:50,C:100, D:500, M:1000};
        var rNA= num.split('');
        var nA= new Array;
        for(var i= 0; i<rNA.length; i++){
        var tem= rNA[i];
        nA[i]= rN[tem];
        }
        i= 0;
        while(i< nA.length-1){
        if(nA[i]< nA[i+1]) return '';
        else sum+= nA[i];
        i++;
        }
        num= sum+nA[i];
        }
        return num;
        }
        Number.prototyp e.toRoman= function(){
        var num= '',tem;
        var n= Math.floor(this );
        var aN= [1, 5, 10, 50,100, 500, 1000];
        var rN= ['I','V','X','L' ,'C','D','M'];
        for(var i= 6; i>= 0;i--){
        if(n> aN[i]){
        tem= Math.floor(n/aN[i]);
        while(tem>0){
        num+= rN[i];
        tem--;
        }
        n= n%aN[i];
        }
        }
        return num;
        }
        return true;
        }[/CODE]

        Math.floor(n/aN[i]) is sure to impress your instructor.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          nchgoguy,

          The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

          Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

          Then when you are ready post a new question in this thread.

          MODERATOR

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by mrhoo
            Math.floor(n/aN[i]) is sure to impress your instructor.
            Not if he can't explain what it does! :)

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by Logician
              Is it O.K. to help people quietly?
              Ooh, that's nasty(!) - a nice pun though!

              Comment

              • Death Slaught
                Top Contributor
                • Aug 2007
                • 1137

                #8
                Originally posted by Logician
                Is it O.K. to help people quietly?
                I personaly believe that's ok as long as you explain the code making it a learning experience.

                - Death

                Comment

                • Death Slaught
                  Top Contributor
                  • Aug 2007
                  • 1137

                  #9
                  Originally posted by acoder
                  Not if he can't explain what it does! :)
                  What does it do exactly?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by Death Slaught
                    What does it do exactly?
                    It divides the number by the current decimal and returns an integer (by 'flooring' the result). For example, if the number was 5050, Math.floor(n/aN[i]) would give Math.floor(5050/1000) which equals 5. This allows the while loop to get 5 Ms.

                    Comment

                    • Death Slaught
                      Top Contributor
                      • Aug 2007
                      • 1137

                      #11
                      Originally posted by acoder
                      It divides the number by the current decimal and returns an integer (by 'flooring' the result). For example, if the number was 5050, Math.floor(n/aN[i]) would give Math.floor(5050/1000) which equals 5. This allows the while loop to get 5 Ms.
                      Nice

                      - Death

                      Comment

                      Working...