By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Assignment on Javascript

P: 1
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]
Nov 21 '07 #1
Share this Question
Share on Google+
10 Replies


Death Slaught
100+
P: 1,137
Sorry we are not aloud to help you on homework assignments, please refer to the Posting Guidelines .

Thanks, Death
Nov 21 '07 #2

100+
P: 210
Sorry we are not aloud to help you on homework assignments.
Is it O.K. to help people quietly?
Nov 22 '07 #3

100+
P: 428
Here is one for Roman numerals. Just rearrange it a bit for your homework.
:
Expand|Select|Wrap|Line Numbers
  1. function check_romandec(){
  2.     String.prototype.fromRoman= function(){        
  3.         var num= '', sum= 0, tem;
  4.         var rGA= [['DCCCC','CM'],['LXXXX','XC'],['VIIII','IX'],['CCCC','CD'],['XXXX','XL'],['IIII','IV']];
  5.         if(/\D/.test(this)==false){
  6.             num= Number(this).toRoman();
  7.             for(var i= 0; i<6; i++) num= num.replace(rGA[i][0],rGA[i][1]);
  8.             return num;
  9.         }
  10.         else{
  11.             var rX= / [^IVXLCDM]/;
  12.             num= this.toUpperCase();
  13.             if(rX.test(num)) return '';
  14.             for(var i= 0;i<6;i++)num= num.replace(rGA[i][1],rGA[i][0]);
  15.             var rN= {I:1, V:5, X:10, L:50,C:100, D:500, M:1000};
  16.             var rNA= num.split('');
  17.             var nA= new Array;
  18.             for(var i= 0; i<rNA.length; i++){
  19.                 var tem= rNA[i];
  20.                 nA[i]= rN[tem];
  21.             }
  22.             i= 0;
  23.             while(i< nA.length-1){
  24.                 if(nA[i]< nA[i+1]) return '';
  25.                 else sum+= nA[i];
  26.                 i++;
  27.             }
  28.             num= sum+nA[i];
  29.         }
  30.         return num;
  31.     }
  32.     Number.prototype.toRoman= function(){
  33.         var num= '',tem;
  34.         var n= Math.floor(this);
  35.         var aN= [1, 5, 10, 50,100, 500, 1000];
  36.         var rN= ['I','V','X','L','C','D','M'];
  37.         for(var i= 6; i>= 0;i--){
  38.             if(n> aN[i]){
  39.                 tem= Math.floor(n/aN[i]);
  40.                 while(tem>0){
  41.                     num+= rN[i];
  42.                     tem--;
  43.                 }
  44.                 n= n%aN[i];
  45.             }
  46.         }
  47.         return num;
  48.     }
  49.     return true;
  50. }
Math.floor(n/aN[i]) is sure to impress your instructor.
Nov 22 '07 #4

acoder
Expert Mod 15k+
P: 16,027
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
Nov 22 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Math.floor(n/aN[i]) is sure to impress your instructor.
Not if he can't explain what it does! :)
Nov 22 '07 #6

acoder
Expert Mod 15k+
P: 16,027
Is it O.K. to help people quietly?
Ooh, that's nasty(!) - a nice pun though!
Nov 22 '07 #7

Death Slaught
100+
P: 1,137
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
Nov 23 '07 #8

Death Slaught
100+
P: 1,137
Not if he can't explain what it does! :)
What does it do exactly?
Nov 23 '07 #9

acoder
Expert Mod 15k+
P: 16,027
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.
Nov 26 '07 #10

Death Slaught
100+
P: 1,137
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
Nov 26 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.