Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Whale Talk
- Take a phrase like ‘turpentine and turtles’ and translate it into its “whale talk” equivalent: ‘UUEEIEEAUUEE’.
- There are a few simple rules for translating text to whale language:
- There are no consonants. Only vowels excluding “y”.
- The u‘s and e‘s are extra long, so we must double them in our program.
- Once we have converted text to the whale language, the result is sung slowly, as is a custom in the ocean.
- To accomplish this translation, we can use our knowledge of loops. Let’s get started!
- */
- let input = "turpentine and turtles";
- const vowels = "AIEU";
- let resultArray = [];
- for(let i=0; i<input.length; i++){
- for(let k=0; k<vowels.length; k++){
- if(input[i] == vowels[k].toLowerCase()){
- resultArray.push(input[i].toUpperCase());
- }
- }
- if(input[i].toLowerCase() == 'e' || input[i].toLowerCase() == 'u'){
- resultArray.push(input[i].toUpperCase());
- }
- }
- console.log(resultArray.join(""));
Advertisement
Add Comment
Please, Sign In to add comment