[Solved] How to get two digit numbers from alphabet assigned numbers


Return call was wrong and function not closing properly

  1. Do not call the same function within a function using return
  2. Inside the function Y is defined one

Updated

send the name with function

function nameNum(name) {

 A = I = J = Q = Y = 1;
  B = K = R = 2;
  C = G = L = S = 3;
  D = M = T = 4;
  E = H = N = X = 5;
  U = V = W = 6;
  O = Z = 7;
  F = P = 8;
console.log('y is '+Y)
  var text = name;
  text = text.replace(/[^a-z]/gi, '');
  text = text.toUpperCase();
  var letters = text.split("")

  var num = (letters.reduce(function(prev, curr) {
    return prev + window[curr];
  }, 0));
  
  return num;
 
}

console.log(nameNum('bani'))

updated with githup link solution

just remove the var

var mennt="bani"; 

function nameNum(name) {
 A = I = J = Q = Y = 1; //remove the var in this line 
  B = K = R = 2;
  C = G = L = S = 3;
  D = M = T = 4;
  E = H = N = X = 5;
  U = V = W = 6;
  O = Z = 7;
  F = P = 8;

  var text = name;
  text = text.replace(/[^a-z]/gi, '');
  text = text.toUpperCase();
  var letters = text.split("")

  var num = (letters.reduce(function(prev, curr) {
    return prev + window[curr];
  }, 0));

  return num;

}

var naNumber = nameNum(mennt);
console.log(naNumber);

6

solved How to get two digit numbers from alphabet assigned numbers