1.7 Victory alternative coding


First post here - I’ve done lots of programming, but JS has always caused me lots of stress, so I’m starting from scratch to try to learn it properly. console.log() is one thing I didn’t know about and it’s very helpful!
I didn’t feel like the approach for this exercise was an ideal one, so I wrote a new technique afterwards using javascript’s search() function. Note: there’s also a similar function called indexOf() but it doesn’t work in some versions of Internet Explorer.
I hope it’s OK to share this code because it won’t enable anyone to cheat on the question. I’ve included code that’ll enable it to open in a browser if saved as .html

<script type="text/javascript">
var text ="paddyhsiohsdoihspaddypaddy--jksdljsdklsdjpaddyksdfpjhsaddykjhypaddjofoidjdiaddyjfodjsopjard7dyjdlsjsyddap";
var myName="paddy";
var matches=0;
var findPosition =0;
while (findPosition > -1) // Keep doing until no more matches are found
	if (findPosition >  -1)
//		console.log(text);
		matches++; // Add one to the number of matches
		text=text.substr(findPosition+myName.length,text.length); // remove the part in which the first match was found

console.log(myName +" was found " + matches + " times.");