Cats and Dogs explainer

The aim of this puzzle: Use JavaScript to create a button and add it to a webpage.

Walkthrough of the solution:
In this puzzle, you’ll use the createElement method, the textContent property, and the appendChild method to create a button and add it to the document body.

To complete the puzzle, create a variable called dogButton that stores a new button element using document.createElement('button'). Then, set the .textContent of dogButton to a string. Finally, append the dogButton element to the body.

To complete the puzzle, create a variable
Sample code solution:
(Tap below to reveal)


let title = document.createElement('h1');
title.textContent = 'Cuteness';

let catImg = document.createElement('img');
catImg.src =  '../../static/images/greyTabby.jpg';

let catButton = document.createElement('button');
catButton.textContent = 'Click Here!';

let dogImg = document.createElement('img');
dogImg.src = '../../static/images/couchDog.jpg';

let dogButton = document.createElement('button');
dogButton.textContent = 'Or Here!';


HTML Concepts: <h1>, <img>, <button>
JavaScript Concepts: .textContent, .createElement(), document body, .appendChild(), Variables

Can some tell me what is wrong in this coding Capture

Hey there, change the string 'Button' to 'button'.

JavaScript is case sensitive, so if you capitalize the B, then document.createElement() doesn’t know what to do with it.

Hope this helps!

I see this error

Hey there, it looks like theres a small typo: an ‘e’ is missing in .createElement. Fixing that should solve the problem.


Can someone please help with my code below? Not sure what I did wrong.

Hey there, it just looks like a few minor capitalization issues. The puzzle wants a variable named dogButton, while you have dogbutton.

Also, try changing textcontent to textContent.

Hope this helps!

Hello Ben,

It worked should have caught that! thank you so much!