Serch your name!

/*jshint multistr:true */ text = "Blah blah blah blah blah blah Eric \ blah blah blah Eric blah blah Eric blah blah \ blah blah blah blah blah Eric"; var myName = "Eric"; var hits = []; // Look for "E" in the text for(var i = 0; i < text.length; i++) { if (text[i] === "E") { // If we find it, add characters up to // the length of my name to the array for(var j = i; j < (myName.length + i); j++) { hits.push(text[j]); } } } if (hits.length === 0) { console.log("Your name wasn't found!"); } else { console.log(hits); }
this is code to search your name!

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.