Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Brian Liles Part 1 HW Print Table with Multiples</title>
  8.  
  9. </head>
  10. <body>
  11.  
  12. <form id="string-entry" onsubmit="return false">
  13. Enter a number:<br>
  14. <input id="myNum"><br><br>
  15. <button id="btn">Generate Table</button>
  16. </form>
  17. <br>
  18. <div id="output">
  19. <table id="myTable">
  20.  
  21. </table>
  22.  
  23. </div>
  24.  
  25.  
  26.  
  27.  
  28. <script type="text/javascript">
  29.  
  30.  
  31.  
  32. document.getElementById("btn").addEventListener("click", printMultiplicationTable);
  33.  
  34.  
  35. function printMultiplicationTable() {
  36. let multiplier = document.getElementById("myNum").value;
  37. let cols = 4;
  38. let rows = 5;
  39.  
  40. // get the reference for the body
  41. var body = document.getElementsByTagName("body")[0];
  42.  
  43. // creates a <table> element and a <tbody> element
  44. var tbl = document.createElement("table");
  45. var tblBody = document.createElement("tbody");
  46.  
  47.  
  48. // creating all cells
  49. for (var i = 0; i < rows; i++) {
  50. // creates a table row
  51. var row = document.createElement("tr");
  52.  
  53. for (var j = 0; j < cols; j++) {
  54. // Create a <td> element and a text node, make the text
  55. // node the contents of the <td>, and put the <td> at
  56. // the end of the table row
  57. var cell = document.createElement("td");
  58. var cellText = document.createTextNode( multiplier * (i*cols) + (j+1));
  59. cell.appendChild(cellText);
  60. row.appendChild(cell);
  61. }
  62.  
  63. // add the row to the end of the table body
  64. tblBody.appendChild(row);
  65. }
  66.  
  67.  
  68. // put the <tbody> in the <table>
  69. tbl.appendChild(tblBody);
  70. // appends <table> into <body>
  71. body.appendChild(tbl);
  72. // sets the border attribute of tbl to 2;
  73. tbl.setAttribute("border", "2");
  74. }
  75.  
  76. </script>
  77.  
  78. <form id="string-entry" onsubmit="return false">
  79. Enter a string:<br>
  80. <input id="myStr"><br><br>
  81. <button id="btn2">REVERSE STRING</button>
  82. </form>
  83. <br>
  84. <div id="output2">
  85.  
  86. </div>
  87.  
  88.  
  89. <script>
  90. document.getElementById("btn2").addEventListener("click", reverseString);
  91.  
  92. function reverseString() {
  93. let str = document.getElementById("myStr").value;
  94.  
  95. str = str.split("").reverse().join("");
  96. document.getElementById("output").innerHTML = str;
  97. };
  98. </script>
  99.  
  100. <div id="output2"></div>
  101.  
  102.  
  103.  
  104.  
  105.  
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement