Log it! problem



The site says "Syntax Problem"

 /*jshint multistr:true */
var text = "Shrike rhjdl;afajd;va'afojvbamld,ng;afvl;acb'a";
var myName = "Shrike";
var hits = [];
  for (i=0; i<text.length; i++) {
      if (text[i]===myName[0]) {
          for (j = i; j=i+myName.length) {
  if(hits.length === 0) {
    console.log("Your name wasn't found!");
else {


If j = i, j will never equal i+myName.length. Also, where is the expression in your for loop?


j= i is just where the loop starts. What do you mean by "expression in my for loop"?



for (j= i ; this part tells the loop where it's starting, the 'initializer'

j= i+myName.length; this part must be true for the loop to run, the 'condition'

The expression is the part that tells the loop what the next value to check for will be.

In your first loop, the expression is i++. So that loop starts scanning from the 1st letter in text to the next, etc. almost all of the way through the characters in that variable. Since your 2nd loop is starting from j, your increment expression should be j++.


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