Console.log isn't a function

I was learning immediate invoke function expression, and when I did the syntax and checked the console, it says “console.log isn’t a function”.

   document.getElementById("myH2").innerHTML = "hey!";



There’s something else going on here. If I copy your script into the console and execute it, it works just fine. Note I had to change document.getElementById(“myH2”) to document.body as I don’t have that ‘#myH2’ element. e.g.

   document.body.innerHTML = "hey!";

So your IIFE function is just fine!

Why did you have to change it to .body?

Why because I ran it in my console (f12 in my browser) and didn’t have an element with an id of ‘myH2’ there. It was just for convenience.

Here is a codepen with your exact line of code working

I did that too but doesn’t work

I don’t know if this is the issue, but you have a capital ‘S’ on src.

<script Src="index.js"></script>

should be

<script src="index.js"></script>

You also have a <head>Enter your Name</head> after your h1 and body. You need to take that out

Wait, I hovered over the X, and it said:


how is student.filter connected to IIFE?


I’m lost @Growly :slight_smile:, too many things going on here and I don’t know what environment you are working in.

Where is students script coming from?

Where is your IIFE script?

Can you put your code into a codepen, might be easier to assist.

I’ve never used that, but I will use it now.

Do I copy everything in js? or just the problem that the X showed?

I copied everything

Wow! Careful what you wish for :laughing:

I will have a scan of it, but not tonight it’s late now.

Just a quick edit:

I think you need to break this down into individual scripts/pens.

It seems you have been trying out all sorts of things, which is great :smiley: , but you have combined them into one big script which isn’t great.

xD, I was doing a tutorial that’s why.

Yes but you should still save these as separate projects. No tutorial is going to have you write one big script consisting of sayHello, celcius conversion, working with objects etc. Individual projects :slight_smile:

:joy: ok


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