JavaScript Simplified / Chapter 117 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

Complete the statement to create a <p> element. let pgraph = ________________; document.createElement("p"); document\.createElement\(•p•\);
Complete the statement to create a text node, "Hello World!" let txt = _______________; document.createTextNode("Hello World!") document\.createTextNode\(•HelloWorld!•\)
Complete the statement to create a blank comment node. let blnkCommment = _____________; document.createComment("") document\.createComment\(••\)
Create a list item. Assign it to a variable, newLI. let newLI = document.createElement("li"); letnewLI=document\.createElement\(•li•\);
Create a new <h2>. Assign it to a variable that hasn't been declared beforehand. Make up the name of the variable. let newHeading = document.createElement("h2"); let[a-z_$][a-zA-Z0-9_$]*=document\.createElement\(•h2•\);
Create a comment. Make up its content. Assign it to a variable that hasn't been declared beforehand. Make up the name of the variable. let newComment = document.createComment("Duh!"); let[a-z_$][a-zA-Z0-9_$]*=document\.createComment\(•.*•\);
Create a text node. Assign it to a variable that hasn't been declared beforehand. Make up the name of the variable. Make up the text content. let textNode = document.createTextNode("Etc."); let[a-z_$][a-zA-Z0-9_$]*=document\.createTextNode\(•.*\.•\);
Create an image element. Assign it a source (a jpg). Make up everything. let newImg = document.createElement("img");
newImg.setAttribute("src", "images/loris.jpg");
let([a-z_$][a-zA-Z0-9_$]*)=document\.createElement\(•img•\);[\r\n]\1\.setAttribute\(•src•,•.*.jpg•\);
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Above my four lines of code, create a <p> element and assign it to a variable, newP.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. If you've coded correctly, new text will appear in the Result panel.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 117 in the book.
  1. Click the HTML button to see my markup. Notice that in the markup the third <p> is empty.
  2. Click the JS button.
  3. Above my code, create a text node that says, "This is new text."
  4. Click the Result button (or, after revising, don't click, just wait).
  5. If you've coded correctly, "This is new text" will appear in the Result panel.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 117 in the book.