Skip to content

Instantly share code, notes, and snippets.

@unes
Last active September 7, 2023 08:53
Show Gist options
  • Save unes/637dd13cc2d18a685c8c2c6b37f3ae40 to your computer and use it in GitHub Desktop.
Save unes/637dd13cc2d18a685c8c2c6b37f3ae40 to your computer and use it in GitHub Desktop.
Whale Talk - JavaScript (from Codecademy)
/*
* translates "turpentine and turtles" to "whale talk" languag, outputs "UUEEIEEAUUEE"
*/
const input = 'turpentine and turtles';
const vowels = ['a', 'e', 'i', 'o', 'u'];
const resultArray = [];
for(let i = 0; i < input.length; i++) {
for(let j = 0; j < vowels.length; j++) {
if (input[i] === vowels[j]) {
resultArray.push(input[i]);
}
}
if (input[i] === 'e') {
resultArray.push(input[i]);
}
if (input[i] === 'u') {
resultArray.push(input[i]);
}
}
console.log(resultArray.join('').toUpperCase());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment