Search text for your name - Log it


Code passed, got the "Start Next Lesson" go ahead. BUT, the print out was 30 empty brackets [ ] one on top of the other. That can't be correct.

/*jshint multistr:true */
var text = "kjbf cfh;Linda irwbldj lib, Linda v biw lb\ b cjbvjb, Linda fboegg bv";
var myName = "Linda";
var hits= [];

for (var i=0; i<text.length; i++) {
   if (text[i] === "L") {
       for (var j=0; j<myName.length +i; j++);
   if (hits.length = 0) {
       console.log("Your name wasn't found!");
   else {


We initialize j to be the current position of i at match found index.

for (var j = i; j < i + myName.length; j++)


Why did 30 [ ] log to the console?


This should have been a comparison, not an assignment.

if (hits.length === 0) {


I made the recommended changes to my code. Now it prints out: 9 "Your name wasn't found!"; 19 [ ' ' ]; 25 [' ' , ' ' ]; and 15 [ ' ', ' ', ' ' ].

I am officially bumfuzzled!


PS: I deleted the environmental mention on my signature per your suggestion. As you so rightly noted, this is not personal correspondence. You might want to re-think your picture -- introducing a baby seems quite personal, maybe better for Facebook.


I like to point out one or two mistakes at a time, and bring up others as the earlier ones are repaired. The above is code that should follow the loop, not be included in it.


Personal if was only yesterday. That picture was taken nearly 40 years ago. My youngest grand child is going on 3 years.


HAHAHAHAHAHA! My apologies!

How long have you been coding? I'm a late starter, late based on age, but I'm enjoying learning, always have . . . .


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