473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assignment on Javascript

1 New Member
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
10 1211
Death Slaught
1,137 Top Contributor
Sorry we are not aloud to help you on homework assignments, please refer to the Posting Guidelines .

Thanks, Death
Nov 21 '07 #2
Logician
210 New Member
Sorry we are not aloud to help you on homework assignments.
Is it O.K. to help people quietly?
Nov 22 '07 #3
mrhoo
428 Contributor
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
16,027 Recognized Expert Moderator MVP
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
16,027 Recognized Expert Moderator MVP
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
16,027 Recognized Expert Moderator MVP
Is it O.K. to help people quietly?
Ooh, that's nasty(!) - a nice pun though!
Nov 22 '07 #7
Death Slaught
1,137 Top Contributor
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
1,137 Top Contributor
Not if he can't explain what it does! :)
What does it do exactly?
Nov 23 '07 #9
acoder
16,027 Recognized Expert Moderator MVP
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
1,137 Top Contributor
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

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

Similar topics

9
1485
by: design | last post by:
Greetings, I have a situation in which an assignment operator isn't working. I'm trying to reset the value of "document.forms.f.shipping.value" to 0. I want this new value to be transmitted when...
8
1157
by: Neil.Jin | last post by:
>>> class A: .... i = 1 .... >>> a = A() >>> A.i 1 >>> a.i 1 >>> A.i = 2 >>> A.i
1
3810
by: oza.hardik | last post by:
Hello, Is there a way to do a verbatim string assignment in JavaScript. Like I could create strings with HTML snippets and reuse in my code. Thanks in advance O
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.