I have limited knowledge of javascript.
When given the string "3005600008000", I need to devise a method that multiplies all the digits in the odd-numbered positions by 2 and those in the even-numbered positions by 1.
This code snippet I drafted seems to output TRUE for the odd numbers (e.g., "0"),
var camid;
var LN= camid.length;
var mychar = camid.charAt(LN%2);
var arr = new Array(camid);
for(var i=0; i<arr.length; i++) {
var value = arr[i]%2;
Alert(i =" "+value);
}
However, I suspect it does not effectively group/split the string at odd (and eventually even) positions.
How can this be accomplished? Any hints would be appreciated.
/=================================================/
The objective is to create a validation routine on a webpage for a smartcard ID number.
The process I aim to implement is as follows:
· 1) Begin from the left side, multiply the digits in the odd-numbered positions by 2 and those in the even-numbered positions by 1.
· 2) In case a single digit multiplied by 2 results in a two-digit number (like "7 x 2 = 14"), sum the resulting digits to obtain a new single-digit outcome ("1+4=5").
· 3) Aggregate all single-digit outcomes.
· 4) The check digit is the amount needed to add to the sum obtained in step #3 to reach the next highest multiple of ten. For instance, if the total in step #3 is 22, adding 8 to 22 will get you to the next highest multiple of 10 (30). Therefore, the check digit is 8.
That's the gist of it. Researching about smartcard ID validation using Google did not return any useful results, leading me to question whether implementing this in Javascript is overly complicated...
Any suggestions are welcome.