TypeError: console.log is not a function. (In 'console.log(hits)', 'console.log' is 69)


#1


Under your existing code (and outside all your loops!), set up an if/else statement. If you don't have any hits, log "Your name wasn't found!" to the console. Otherwise, log the hits array to the console.


TypeError: console.log is not a function. (In 'console.log(hits)', 'console.log' is 69)
Oops, try again. Did you remember to log the result of your search to the console?

Replace this line with your code. 
/*jshint multistr:true */
var text = "Vorrei che Dario riuscisse ad insegnare a Dario\
come programmare bene DarioJs";
var myName = "Dario";
var hits = [];
for (i=0; i < text.length; i++) {
    if (text[i] === "D")
    {
        console.log= i;
        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);
}


#2

Problem.

console.log= i;
Can you explain what are you trying to do at this line of code?


#3

:smiley: actually don't know. It accepted it some steps back and I didn't complain. Anyway, if I erase it returns the same error but console.log is 76


#4

Revision 2.0 -- console.log()

console.log(data) -- prints something(data) out ,

to print something out,you need to put it inside the ( ) i.e Parentheses

try that and tell what you get.. ok?


#5

I changed in
console.log= (i);

but nothing changed


#6

console.log= (i);
Can you tell me difference between these two ?

console.log(5) and console.log=(6)

?

hint**
You dont need = .


#7

Sorry but I still really suck at coding (or learning to code) so I didn't notice till now.
Removed the =
but same story, same error.


#8

updated**

You have to use console.log(i);
or
You can try removing it.


#9

nono, I removed "=" but the line is still there.
Anyway everything was fine till I add the last if statement. Don't know what's wrong. It's the same of the first exercise of the chapter . I read also other people has it but someone fixed it refreshing the page. I refreshed, clicked on reset code and even logged out/logged in.


#10

Okay put your code here..
and also tell what errror you're getting now


#11

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

/*jshint multistr:true */
var text = "Vorrei che Dario riuscisse ad insegnare a Dario\
come programmare bene DarioJs";
var myName = "Dario";
var hits = [];
for (i=0; i < text.length; i++) {
    if (text[i] === "D")
    {
        console.log (i);
        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);
}

Oops, try again. Did you remember to log the result of your search to the console?

TypeError: console.log is not a function. (In 'console.log (i)', 'console.log ' is 69)


#12

Your code works fine, Can you see?

Ps: you don't need console.log(i) there ,You need it when you wanted to test your code or visualize looping .
It has no effect on overall code, You can take it out(ersae it)!


#13


#14

still using console.log = i; ?

you don't need console.log(i) there ,You need it when you wanted to test your code or visualize looping .
It has no effect on overall code, You can take it out(ersae it)!


#15

Sorry, anyway even without it nothing changes
I've even changed the browser, logged in again, but nothing.


#16

Ok,post your raw code,same one that you have shown in snap!


#17

Here it is, anyway i skipped to the next chapter to see what happen. It's the last of the module so I just had to click Save and Submit, and it worked. Maybe a bug?

/*jshint multistr:true */
var text = "Vorrei che Dario riuscisse ad insegnare a Dario\
come programmare bene DarioJs";
var myName = "Dario";
var hits = [];
for (i=0; i < text.length; i++) {
    if (text[i] === "D")
    {
       // console.log (i);
        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);
}

#18

This code runs smoothly on my browser(Chrome).
Maybe there is some issue!
1. Try using firefox
2.delete history/cache files


#19

I usually use safari but in this occasion i also tried firefox. Don't know.
Thank you so much anyway!
Let's While now! :wink:


#20

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