Number 6 log it


#1


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


I run the code and I am told I have a syntax error. I spent hours trying out every combination. I even added a correct if else statement from another discussion topic to the code that ran before and modified them to fit together yet still I get 'syntax error' and the code won't run. Please help me by telling me what I did wrong?


/*jshint multistr:true */
var text="TomTom"
var myName="Tom"
var hits =[]
for(var i=0;i<text.length; i++){
   if(text[i] === 'T'){
   

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


#2

End with a semi-colon (:wink: here:

Remove both curly braces, here:

This whole loop doesn't look right.

See below:

/*jshint multistr:true */

var text = "TomTom"
var myName="Tom"
var hits = [];
for (var i=0; i < text.length; i++)
if (text[i] === "T")
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);
}

#3

thanks a lot for your help


#4

You're welcome.

Have fun coding! :slight_smile:


#5

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