Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add an erase feature to the drawing program below code . Try setting the backgro

ID: 3534259 • Letter: A

Question

  Add an erase feature to the drawing program below code. Try setting the background color of the table cell over which the mouse moved to white when theAlt key is pressed <!DOCTYPE html>


<!-- draw.html -->
<!-- A simple drawing program. -->
<html>
  <head>
<meta charset="utf-8">
<title>Simple Drawing Program</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script src = "draw.js"></script>
  </head>
  <body>
<table id = "canvas">
  <caption>Hold <em>Ctrl</em> (or <em>Control</em>) to draw blue.
Hold <em>Shift</em> to draw red.</caption>
  <tbody id = "tablebody"></tbody>
</table>
  </body>
</html>

Explanation / Answer

function erase() {

// Get all of the TDs inside of my table body

var allTDs = document.getElementById("tablebody").getElementsByTagName("td");

// Loop over them all

for (i = 0; i < allTDs.length; i++) {

// Set the background color to white

allTDs[i].style.backgroundColor = "white";

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote