I was hoping to get some advice on a script I'm playing with. I'm working on a program that counts numerous elements of a sentence and right now I'm just counting the vowels in total. I have a working script but I was wondering, is there a better way to do this than what I have so far?
HTML
<div id="test">
<input type="text" />
<p></p>
<p></p>
</div>
JS
$(document).ready(function(){
var key;
var vowels;
$("#test input[type='text']").on("keydown", function(e){
key = e.target.value;
$("#test p:nth-of-type(1)").text(key);
})
$(this).on("keydown", function(e){
vowels = [];
if(e.keyCode == 13){
console.log($("#test input[type='text']").val());
for(var i = 0; i < $("#test input[type='text']").val().length; i++){
switch($("#test input[type='text']").val()[i]){
case "a":
vowels.push($("#test input[type='text']").val()[i]);
break;
case "e":
vowels.push($("#test input[type='text']").val()[i]);
break;
case "i":
vowels.push($("#test input[type='text']").val()[i]);
break;
case "o":
vowels.push($("#test input[type='text']").val()[i]);
break;
case "u":
vowels.push($("#test input[type='text']").val()[i]);
break;
}
}
$("#test p:nth-of-type(2)").text("There are " +vowels.length +" vowels.");
}
})
})
Here's the Working Pen.