Click to See Complete Forum and Search --> : can some explain this code


graemo
12-11-2002, 11:17 AM
could someone please explain this code to me step by step as i'm pretty new to this and need to understand!!

also I have a program with a.splice in it ......

return a.splice( parseInt(Math.random() * a.length), 1 );

but it wont work anyone any ideas as to what to change it to.

all help gratefully appreciated...



function checkNumber(number)
{
if(((number) < 10000) && ((number) > 0))
{
var numeral = createNumeral(number);
{
window.document.form.numeral.value = numeral;
}
}else{
alert('You have entered an invalid number!!');
}
}
function createNumeral(num)
{
var new_num = num
var thousands = Math.floor(new_num / 1000);
new_num -= thousands * 1000;
var hundreds = Math.floor(new_num / 100);
new_num -= hundreds * 100;
var tens = Math.floor(new_num / 10);
new_num -= tens * 10;
var ones = Math.floor(new_num / 1);
{
var array = new Array(thousands,hundreds,tens,ones);
return makeNumeral(array);
}
}
function makeNumeral(place_values)
{
var numeral = "";
numeral += thousands_value[place_values[0]];
numeral += hundreds_value[place_values[1]];
numeral += tens_value[place_values[2]];
numeral += ones_value[place_values[3]];
return numeral;


cheers
Graemo

Charles
12-11-2002, 12:09 PM
1) There is no String.splice() method in JavaScript. See http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm for a description of what you can do with strings.

2) That's a prety bad piece of code to be studying. See the Roman.prototype.toString() method from my other post for a much more simple and straight forward way of getting Roman numerals.