Where am I going wrong?!


#1


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


Error message: "Oops, try again. Did you remember to log the result of your search to the console?"
Output: ["C","a","m","m","i","l","l","i","u","s","C","a","m","m","i","l","l","i","u","s","C","a","m","m","i","l","l","i","u","s","C","a","m","m","i","l","l","i","u","s"]


/*jshint multistr:true */
var text = "Cammillius Cammillius Cammillius Cammillius"; 
var myName = "Cammillius";
var hits = [];
for (var i = 0; i < text.length; i++)
{
    if (text[i] === myName[0])
    {
        for (var j = 0; j < myName.length; j++)
        {
            hits.push(text[j]);
        }
        
    }
}
 if (hits.length==0)
 {
     console.log = ("Your name was not found!");
     
 }
 else
 {
     console.log = (hits);
 }


#2

Are you sure = is used to call functions?


#3

Thanks a lot for the reply. . .
If I made the following change:
if(hits.length===0)
{
console.log("Your name was not found!");

}
else
{
console.log(hits);
}

And got this error: "Oops, try again. Did you remember to log the result of your search to the console?"


#4

If you didn't refresh page after overwriting console.log, then you'll need to do that to get the function back


#5

Thanks a lot! The code worked!!! Just as you said, I had to only refresh the page. . . :slight_smile:


#6

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