Step 19 in "Chore Door". I can't open the doors

So I have code from the Chore Door project, but I can’t post anything with more than 1 img link or something like that, since I’m a “New user”. My code below is therefor with removed links.

I’m stuck at step 19, cant open doors, cant figure out why. I get this at jsbin: "“TypeError: Cannot set property ‘onclick’ of null”.

Heres my code - with links removed, and hopefully my mistakes aren’t among those:

EDIT: I apparently cant post the HTML here. No idea why. It leaves only the script element in a gray box, but removes everything else when I post.

HTML

Chore Door!
<script type="text/javascript" src="script.js"></script>

CSS
body {
background-color: #010165;
margin: 0px;
}

.door-frame {
cursor: pointer;
padding: 10px;
}

JavaScript
let doorImage1 = document.getElementById(door1);
let doorImage2 = document.getElementById(door2);
let doorImage3 = document.getElementById(door3);

let botDoorPath = “”
let beachDoorPath = “”
let spaceDoorPath = “”

doorImage1.onclick = () => {
doorImage1.src = “”;
}

doorImage2.onclick = () => {
doorImage2.src = “”;
}

doorImage3.onclick = () => {
doorImage3.src = “”;
}

1 Like

Hey @robert.b.norbygmail!

Are door1, door2, and door3 the names of a variable or the id document.getElementById() is supposed to equal?

Because if they are supposed to be an ID in the html, then you need to surround them with quotation marks.

1 Like

Also the reason the HTML disappears is because you cannot write HTML code in these discussion posts.

To fix this, surround your HTML code with three ``` marks

So for example

image

Format it like that and it should show the HTML code

1 Like

Hey!

Yeah - that solved it. Thanks!

But a bit puzzling I must point out. I mean, the rule is what it is, and that’s fine. But at step 10 in this exercise, you have set up 1 door, right. And when trying that on jsbin, it worked. Door opened. Then, from there you basically just copy paste your code and change out the ID’s etc - same code and logic - to get the other 2 doors. Now at step 19, no door works - including the first one that previously DID work (even though it had “door1” but without quotation marks.)

Anyhow. That is not a big concern for me right now, so I will take my bow, and carry on with the exercive :slight_smile:

Thanks again.

1 Like