Replace a letter with its alphabet position

This looked fairly straightforward to me when I started, but for some reason I’m getting an empty array everytime I try to run the result on codewars. I’m hoping you can help me identify what the problem is.

function alphabetPosition(text) {
  text.split(' ').join('');
  var chari = "";
  var arr = [];
  var alphabet = "abcdefghijklmnopqrstuvwxyz".split('');
  for(var i = 0; i < text.len; i++){
    chari = text.charAt(i).toLowerCase();
    if(alphabet.indexOf(chari) > -1){
  return arr;
console.log(alphabetPosition("Hello World"));

My idea is to get the text from the parameter then strip out the spaces. I made a variable for my empty array and make an alphabet string that I can later search through. In the for loop, i make each character lowercase, and if the character is found in the alphabet string, its position gets pushed into the array (arr). I appreciate your time.

14 thoughts on “Replace a letter with its alphabet position”

  1. 738610 415849OK 1st take a excellent appear at your self. What do you like what do you not like so considerably. Work on that which you do not like. But do not listen to other men and women their opinions do not matter only yours does. Work on having the attitude that this is who you are and if they dont like it they can go to hell. 969314


Leave a Comment