outlawstar4761
In Runtime
- Messages
- 186
When using the "indexOf" and "lastIndexOf" operators to count occurences of substrings how can you make JS check for more than one. The example I read only looks for one word. But the one I'm making requires looking for each vowl.
<html>
<script language=JavaScript>
var WooT = prompt("plz enter some text: ")
var foundAtPosition = 0;
var wroxcount = 0;
while (foundAtPosition != -1 )
{
foundAtPosition = WooT.indexOf("A" + "E" + "I" + "O" + "U", foundAtPosition);
if (foundAtPosition != -1)
{
wroxcount++
foundAtPosition++
}
}
document.write("There are " + wroxcount + " occurences of capital vowls");
</script>
There's the code
Thanks
<html>
<script language=JavaScript>
var WooT = prompt("plz enter some text: ")
var foundAtPosition = 0;
var wroxcount = 0;
while (foundAtPosition != -1 )
{
foundAtPosition = WooT.indexOf("A" + "E" + "I" + "O" + "U", foundAtPosition);
if (foundAtPosition != -1)
{
wroxcount++
foundAtPosition++
}
}
document.write("There are " + wroxcount + " occurences of capital vowls");
</script>
There's the code
Thanks