benjaminvr

Codecademy - Whale talk

Jul 20th, 2021
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Whale Talk
  3. Take a phrase like ‘turpentine and turtles’ and translate it into its “whale talk” equivalent: ‘UUEEIEEAUUEE’.
  4.  
  5. There are a few simple rules for translating text to whale language:
  6.  
  7. There are no consonants. Only vowels excluding “y”.
  8. The u‘s and e‘s are extra long, so we must double them in our program.
  9. Once we have converted text to the whale language, the result is sung slowly, as is a custom in the ocean.
  10.  
  11. To accomplish this translation, we can use our knowledge of loops. Let’s get started!
  12. */
  13.  
  14. let input = "turpentine and turtles";
  15.  
  16. const vowels = "AIEU";
  17. let resultArray = [];
  18.  
  19. for(let i=0; i<input.length; i++){
  20.   for(let k=0; k<vowels.length; k++){
  21.     if(input[i] == vowels[k].toLowerCase()){
  22.       resultArray.push(input[i].toUpperCase());
  23.     }
  24.   }
  25.   if(input[i].toLowerCase() == 'e' || input[i].toLowerCase() == 'u'){
  26.         resultArray.push(input[i].toUpperCase());
  27.   }
  28. }
  29.  
  30. console.log(resultArray.join(""));
Advertisement
Add Comment
Please, Sign In to add comment