This is a course project for a simple search counter for the word "Wrox" in a string.
My code:
var myString = "Welcome to Wrox books. ";
myString = myString + "The Wrox website is www.wrox.com. ";
mystring = myString + "Visit the Wrox website today. Thanks for buying Wrox. ";
var i = 0;
var wroxCount = 0;
while (i <= myString.length) {
i = myString.indexOf("Wrox",i);
wroxCount++;
i++;
}
It works fine until i
decides to reset to -1
for some reason. It works until it suddenly doesn't. I don't know what I'm doing wrong.