Skip to content

Instantly share code, notes, and snippets.

@quinton-c
Created February 23, 2021 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quinton-c/f4fb87e053001dd1c98cdf91aaeda569 to your computer and use it in GitHub Desktop.
Save quinton-c/f4fb87e053001dd1c98cdf91aaeda569 to your computer and use it in GitHub Desktop.
whale translator
//set input equal to the phrase you wish to translate into whale
let input = 'turpentine and turtles';
const vowels = ['A', 'E', 'I', 'O', 'U'];
let resultArray = []
for (let i = 0; i < input.length; i++) {
for (let v = 0; v < vowels.length; v++) {
if (input[i].toUpperCase() === vowels[v]) {
if (input[i].toUpperCase() === 'U' || input[i] === 'E') {
resultArray.push(vowels[v], vowels[v]);
} else resultArray.push(vowels[v]);
}
// console.log(i, v); prints current i and v for each iteration of inside loop
}
// console.log(i); prints i for each iteration of outside loop. these logs provide a good visual for how the loops iterate through the code (or how the code iterates throug the loops?)
}
console.log(resultArray.join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment