how to move to the next string's character in java Script?

92 views Asked by At

I have to make the abbreviation function in JavaScript, but whatever I do, I can not find the way to abbreviate a phrase such as 'National Aeronautics Space Administration' to NASA. I just can return N. here is the code I wrote:

function makeAbbr(words) {
 let abbreviation = words.trim();
 for (let i=0; i< words.length; i++){
  if(words[i]!==''){
   return abbreviation.toUpperCase().charAt(0);
 }if(words[i]===''){
   abbreviation+= words.charAt();
 }
}
}
1

There are 1 answers

0
Murtuza On

Try giving a white space instead of empty string

words[i]!==' '

Apply this to else portion also