Here are some different methods for comparison:
One approach is using a series of if statements, with a more compact syntax utilizing a for loop.
var text = prompt("Enter Lance's message");
//user inputs any text
var result = "";
for (var i in text) {
var ch = text.charAt(i);
if (ch == "e" || ch == "o" || ch == "a" || ch == "u") {
result = result + "i";
} else {
result = result + ch;
}
}
console.log(result);
Another method is using a switch statement
var text = prompt("Enter Lance's message");
//user inputs any text
var result = "";
for (var i in text) {
var ch = text.charAt(i);
switch (ch) {
case "e": case "o": case "a": case "u":
result = result + "i"
break;
default:
result = result + ch;
break;
}
}
console.log(result)
Lastly, you can use regular expressions and a ternary operator along with the += operator to append values to a string
var text = prompt("Enter Lance's message");
//user inputs any text
var result = '';
for (var i in text) {
result += function(ch) {
return ch.match(/[eoau]/) ? "i" : ch
}(text.charAt(i));
}
console.log(result);
Best of luck with your learning endeavors!