5- syntax error PLEASE HELP FAST


#1


https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#


error messages say unexpected token but I can't find it. THANKS FOR THE HELP!!


/*jshint multistr:true */

var text = "hello hello gello chris bruh chris bruh bruh bruh";
var myName = "chris";
var hits = [];

for (var i = 0; text.length > i; i++) {
   
    if (myName[i] === text["c"])  {
        
        for(var j = i;i+myName.length; j++;) {
            hits.push(text[j]);
        
      };
        
   };
};


#2

You have 3 problems:

for (var i = 0; text.length > i; i++) { ... }

change to i < text.length

if (myName[i] === text["c"])

change to

if (myName[i] === text[0]) {...}
// OR
if (myName[i] === "c" {...}

and here:

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

you have syntax error: remove ; after j++.

As a result, should be:

var text = "hello hello gello chris bruh chris bruh bruh bruh";
var myName = "chris";
var hits = [];

for (var i = 0; i < text.length; i++){
    if (text[i] === myName[0]){
        for(var j = i; j < i + myName.length; j++){
            hits.push(text[j]);  
        }
    }    
}
console.log(hits);

#3

THANKS SO MUCH dude it was a great help


#4

3 posts were split to a new topic: Can you tell me what the problem is with my code?


#9