Simple solution for "Search Text for Your Name"


#1

Have a look at this simple solution.
I understand the use of arrays, loops and if/else statements in the lesson for the sake of practice, but the example should have been one that makes use of these in a way that makes more sense.

var string = "Hey, hello, my name is John.\
	Is your name John too? Johnny is not john.";
substring = "John";
var count = string.split(substring).length -1;

if (count > 0)
{
  console.log(substring + " appears " + count + " times in the above string");
}
else
{
  console.log("Your name was not found")
};


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.