6.Log it! Syntax error


#1


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


I am not quite sure what I am missing here. I am receiving this message "Oops try again. There was a problem with your syntax." Can anyone spot any mistakes I have made here?. Thanks.

/*jshint multistr:true */
var text = "Hi my name is Benito\
and my full name is Benito Sebastian.";

var myName = "Benito";
var hits = [];

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


#2

Before your last "if - else" instruction - there shouldn't be any semicolons :wink: this is not a function.


#3

Hi @olinka770 , I think I have corrected that problem but its still showing me the same error.

/*jshint multistr:true */
var text = "Hi my name is Benito\
and my full name is Benito Sebastian.";

var myName = "Benito";
var hits = [];

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

if (hits.length === 0) {
console.log("Your name wasn't found!");
} else {
console.log(hits);
};
};

Can you spot any other bugs?
Thanks for helping.


#4

/*jshint multistr:true */
var text = "Dzień dobry \
, mam na imię ola.";
var myName = "ola";
var hits = [];
for(var i = 0; i < text.length; i++)
{
if(text[i] === "o")
{
for(var j = i; j < i+myName.length; j++)
{
hits.push(text[j]);
}
}

}
if(hits.length === 0)
{
console.log("Your name wasn't found.");
}
else
{
console.log(hits);
}


#5

for(var i = 0; i < text.length; i++) //check this loop - you have deleted sth from this for loop


#6

you should to delete some semicolons from your code as well :wink:


#7

Thanks a lot Olinka770. Problem solved :smiley:


#8

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