It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Hello ALL, serious JavaScript Problem

Hello ALL, serious JavaScript Problem

Postby jud on Sun Apr 26, 2009 7:42 pm

Hi,

I wrote this script in order to calculate and id number, if it is fake or not...:
CODE:
function valId (s)
{
alert ("ENTERD function valId");
if (s.length < 5)
alert ("ID 2 SHORT!!!!");
else
{
alert ("ENTERED FIRST ELSE...");
var i;
temp:integer = 0;
total:integer = 0;

// loops through id num and calculates SUM = total
for (i = s.length - 1; i >= 0; i--)
{
alert ((s.charAt(i)).toString());
if ((i % 2) == 0)
{
temp = s.charAt(i)*2;
if (temp >9)
{
alert ("GADOL ME 9");
temp = temp - 10;
total = total + temp +1;
}
else
total = total + temp;
}
else
{
total = total + s.charAt(i);
}
alert ((total).toString());
}

}
if ((total % 10) == 0)
alert ("GOODID");
else
alert ("BADID");
return returnString;
}
</script>


SOMEHOW the code concatenates = gives a string instead of giving out the methematical result....

CAN ANY 1 TELL WHERE I AM GOING WRONG???

THANX A MILLION....
JUD.
jud
 
Posts: 1
Joined: Sun Apr 26, 2009 7:22 pm

Who is online

Users browsing this forum: No registered users and 6 guests