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]
10 1211
Sorry we are not aloud to help you on homework assignments, please refer to the Posting Guidelines .
Thanks, Death
Sorry we are not aloud to help you on homework assignments.
Is it O.K. to help people quietly?
Here is one for Roman numerals. Just rearrange it a bit for your homework.
: - function check_romandec(){
-
String.prototype.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)==false){
-
num= Number(this).toRoman();
-
for(var i= 0; i<6; i++) num= num.replace(rGA[i][0],rGA[i][1]);
-
return num;
-
}
-
else{
-
var rX= / [^IVXLCDM]/;
-
num= this.toUpperCase();
-
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.prototype.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;
-
}
Math.floor(n/aN[i]) is sure to impress your instructor.
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
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! :)
acoder 16,027
Recognized Expert Moderator MVP
Is it O.K. to help people quietly?
Ooh, that's nasty(!) - a nice pun though!
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
Not if he can't explain what it does! :)
What does it do exactly?
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
by: Neil.Jin |
last post by:
>>> class A:
.... i = 1
....
>>> a = A()
>>> A.i
1
>>> a.i
1
>>> A.i = 2
>>> A.i
|
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
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |