0

Hi so basically I have a prompt that will make the user enter a phrase or phrases and when I return it I need to make each word an acronym and capital letter, for example: If I wrote "hello welcome to canada" it should come up as "HWTC". I have to use a either a for loop or while loop to do this and this is what I have right now but not sure how to make it so every word comes up as an acronym instead of just the first word I write. Thanks

function acronym () {
   let word = prompt("enter a word that you want to change into an acronym")
   let result = word
   while (word.charAt(4) === "") {
       word = word.charAt(0)
       word = word.toUpperCase()
   } document.getElementById("string").innerHTML = result;
}   
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
  • 2
    Possible duplicate of [How to capitalize first letter of each word, like a 2-word city?](https://stackoverflow.com/questions/4878756/how-to-capitalize-first-letter-of-each-word-like-a-2-word-city) – Daniel Feb 04 '18 at 03:40
  • That isn't right, I need to use a for or while loop to do this. While the link you gave me gave me some solution, it isn't the one I'm looking for – Bradley Lim Feb 04 '18 at 22:49

0 Answers0