Hi all!!!!
By the title I would replace the letters, but without use the method replace
Insert in a VAR even = ABCD, and in an other VAR odd = EFGH; and now I have to replace these letters with an number specific!!! Ex:
Value Convert
A 1
B 4
C 12
D 6
E 8
F 17
G 9
H 2
Now I have used an Array, but don't work, because after I had write the Array, I don't say how to do!!
Code:
(This is example that I have used, but it's a Fail!)
var myWord = ["1","4","12",.....];
for (myWord = 0; myWord < value.length; i++)
<script type = "text/javascript">
var letters =["A","B","C", "D", "E", "F", "G", "H"];
var numbers = [ "1", "4", "12", "6", "8", "17", "9", "2"]
var result = [];
var word = "HABFACDEFGH";
var wordsplit = word.split("");
for (var i=0; i < wordsplit.length; i++) {
for (var j = 0; j <letters.length; j++) {
if (wordsplit[i] == letters[j]) {
result[i] = numbers[j];
}
}
}
var output = result.join (" ");
alert (output);
</script>
“Sex is one of the most wholesome, beautiful and natural experiences that money can buy.” - Steve Martin
Yes yes, like this, have only one problem, that the value is in String, and after i need to add all number, so i used parseInt, to come back all value in number!! But yes, my Idea is this
Yes yes, like this, have only one problem, that the value is in String, and after i need to add all number, so i used parseInt, to come back all value in number!! But yes, my Idea is this
Don't use parseint() - use Number()
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
var myLetters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var numbersOdd = ["1","0","5","7","9","13","15","17","19","21","1","0","5","7","9","13","15","17","19","21","2","4","18","20","11","3","6","8","12","14","16","10","22","25","24","23"]
var numbersEven = ["0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]
var result = [];
var wordOdd;
//txTotal, is the function that contenent my string of 15 (word and number ex: brtnce43r0e890s)
wordOdd = txTotal.charAt(0) + txTotal.charAt(2) + txTotal.charAt(4) + txTotal.charAt(6) + txTotal.charAt(8) + txTotal.charAt(10) + txTotal.charAt(12) + txTotal.charAt(14);
var wordOddSplit = wordOdd.split("");
for (i = 0; i < wordOddSplit.length; i++) // Yhe debugger sign hre the error!!! Why???
{
for (k = 0; k < myLetters.length; k++)
{
if (wordOddSplit[i] == myLetters[k])
{
result[i] = numbersOdd[k];
}
}
}
var output = result.join (" ");
alert (output);
Yes sorry!
I have the final var resuls = 1 13 7 5 9 10 4,
Now it's possible add al value? 1+13+7+5+9+10+4 and obtain the result? = 49, in other var?
Yes, of course it is possible. But I think you should make an attempt to do this yourself. It is very easy. It can be done in one line of code.
You need to convert each element of the result array to a number (it is a string at present because you have placed your numbers in quotes thus "13") and add them all together.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Yes, of course it is possible. But I think you should make an attempt to do this yourself. It is very easy. It can be done in one line of code.
You need to convert each element of the result array to a number (it is a string at present because you have placed your numbers in quotes thus "13") and add them all together.
Now don't work the first part... O god, that disaster!!!
Test it, with a var name = "aaabbb93r02e970", the result return is 1 1 1 0 0 0 21 7 11 1 5 9 21 17 1. At me return only 5 number random!
Code:
function calculatePinControl (txTotal)
{
var myLetters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var numbersOdd = ["1","0","5","7","9","13","15","17","19","21","1","0","5","7","9","13","15","17","19","21","2","4","18","20","11","3","6","8","12","14","16","10","22","25","24","23"]
var numbersEven = ["0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]
var result = [];
var wordOdd = "";
//txTotal, is the function that contenent my string of 15 (word and number ex: brtnce43r0e890s)
wordOdd = txTotal.charAt(0) + txTotal.charAt(2) + txTotal.charAt(4) + txTotal.charAt(6) + txTotal.charAt(8) + txTotal.charAt(10) + txTotal.charAt(12) + txTotal.charAt(14);
var wordOddSplit = wordOdd.split("");
for (i = 0; i < wordOddSplit.length; i++)
{
for (k = 0; k < myLetters.length; k++)
{
if (wordOddSplit[i] == myLetters[k])
{
result[i] = numbersOdd[k];
}
}
}
var output = result.join (" ");
alert (output);
}
Sorry I read and test again and I'm understanding error!!!
Now I find a solution for convert the split in number
Yes, of course it is possible. But I think you should make an attempt to do this yourself. It is very easy. It can be done in one line of code.
You need to convert each element of the result array to a number (it is a string at present because you have placed your numbers in quotes thus "13") and add them all together.
I don't find a solution! I test this!!!
Code:
var letters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var numbers/*Odd*/ = ["1","0","5","7","9","13","15","17","19","21","1","0","5","7","9","13","15","17","19","21","2","4","18","20","11","3","6","8","12","14","16","10","22","25","24","23"]
var numbersEven = ["0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]
var result = [];
var wordOdd = "";
//txTotal, is the function that contenent my string of 15 (word and number ex: brtnce43r0e890s)
var word = "btc9r290";
var wordsplit = word.split("");
for (var i=0; i < wordsplit.length; i++)
{
for (var j = 0; j <letters.length; j++)
{
if (wordsplit[i] == letters[j])
{
result[i] = numbers[j];
}
}
}
var output = result.join (" ");// var output = result;
var out = output.parseInt(output);//var out = output.parseInt();//var out = output.number(result);//var out = output.number(output);// var out = number(output);// (What am I doing) xD
I don't have idea for oyu line easy easy!!!
var ciao;
alert (output);
return output;
}
var total = 0;
for (var j = 0; j <letters.length; j++) {
if (wordsplit[i] == letters[j]) {
result[i] = numbers[j];
total += (number[j]*1); // make number[j] a number
}
}
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
var total = 0;
for (var j = 0; j <letters.length; j++) {
if (wordsplit[i] == letters[j]) {
result[i] = numbers[j];
total += (number[j]*1); // make number[j] a number
}
}
Is this your solution add at my problem but the result that return it's the same string and don't number added themselves
Code:
function calculatePinControl (txTotal)
{
var letters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
var numbers= ["1","0","5","7","9","13","15","17","19","21","1","0","5","7","9","13","15","17","19","21","2","4","18","20","11","3","6","8","12","14","16","10","22","25","24","23"]
var result = [];
var wordOdd = "";
//txTotal, is the function that contenent my string of 15 (word and number ex: brtnce43r0e890s)
word = "rsslrt93r02e970"
var wordsplit = word.split("");
var total = 0;
for (var i=0; i < wordsplit.length; i++)
{
for (var j = 0; j <letters.length; j++)
{
if (wordsplit[i] == letters[j])
{
result[i] = numbers[j];
total += (numbers[j]*1);
}
}
}
var output = result.join (" ");
alert (output);
return output;
}