I have two queries in this issue. I am writing a PigLatin code in JavaScript in which the following words are supposed to return the following responses:
"computer" == "omputercay"
"think" == "inkthay"
"algorithm" == "algorithmway"
"office" == "officeway"
"Computer" == "Omputercay"
"Science!" == "Iencescay!"
However my code returns the following responses for the last two words: "omputerCay" and "ience!Scay". The first query I have is to find out how to capitalise the first letter of omputerCay and make the "C" lowercase. The second is to do the same thing but also move the "!" to the end of the word.
The suggested articles did not help move the "!" to the end of the word.
function pigLatin(str) {
let vowels = ['a', 'e', 'i', 'o', 'u'];
let newStr = "";
if (vowels.indexOf(str[0]) > -1) {
newStr = str + "way";
return newStr;
} else {
let firstMatch = str.match(/[aeiou]/g) || 0;
let vowel = str.indexOf(firstMatch[0]);
newStr = str.substring(vowel) + str.substring(0, vowel) + "ay";
return newStr;
}}