Skip to content

Instantly share code, notes, and snippets.

@Higokian
Created June 6, 2020 22:01
Show Gist options
  • Save Higokian/fbfe3014842e77d8a7539f0c061f3960 to your computer and use it in GitHub Desktop.
Save Higokian/fbfe3014842e77d8a7539f0c061f3960 to your computer and use it in GitHub Desktop.
Whale translator - Translates words into wale language
// Create input variable and necessary
// arrays
let input = 'hello, human';
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];
// Create for loop to sift through each letter
// of the input and compare them to vowels
// (whale letters)
for(i = 0; i < input.length; i++) {
//console.log(i);
for(j = 0; j < vowels.length; j++) {
if(input[i] === vowels[j]) {
resultArray.push(vowels[j]);
}
}
// Inside outer loop, double 'e' and 'u' vowels
if(input[i] === 'e') {
resultArray.push(input[i]);
}
if(input[i] === 'u') {
resultArray.push(input[i]);
}
}
// Log the input translated to whale
console.log(resultArray.join('').toUpperCase());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment