main.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //Таблица умножения
  2. let multiplyTable = []
  3. for (let i = 0; i <=10; i++) {
  4. multiplyTable[i] = []
  5. for (let j = 0; j <=10; j++) {
  6. multiplyTable[i][j] = i * j
  7. }
  8. }
  9. let tableContainer = document.querySelector('.multipleTable')
  10. let table = document.createElement('table')
  11. table.border = "1"
  12. for (let i = 0; i < multiplyTable.length; i++) {
  13. let row = document.createElement('tr')
  14. if (i == 0) {
  15. let cell = document.createElement ('td')
  16. cell.innerHTML = '&#9959;'
  17. row.appendChild(cell)
  18. } else {
  19. let cell = document.createElement('td')
  20. cell.innerText = i
  21. row.appendChild(cell)
  22. }
  23. for (let j = 1; j < multiplyTable[i].length; j++) {
  24. if (i == 0) {
  25. let cell = document.createElement('td')
  26. cell.innerText = multiplyTable[1][j]
  27. row.appendChild(cell)
  28. } else {
  29. let cell = document.createElement('td')
  30. cell.innerText = multiplyTable[i][j]
  31. row.appendChild(cell)
  32. }
  33. }
  34. table.appendChild(row)
  35. }
  36. tableContainer.appendChild(table)
  37. //Подсветить ячейку
  38. let cells = document.querySelectorAll('td');
  39. let colors = ['#FEE0FF', '#FED6BC', '#FFFADD', '#DEF7FE', '#E7ECFF', '#C3FBD8', '#FDEED9', '#F6FFF8', '#B5F2EA', '#C6D8FF']
  40. for (let cell of cells) {
  41. cell.onmouseover = function () {
  42. cell.style.transitionDuration = '0s'
  43. let colorIndex = Math.floor(Math.random() * colors.length)
  44. cell.style.backgroundColor = colors[colorIndex]
  45. }
  46. }
  47. for (let cell of cells) {
  48. cell.onmouseout = function () {
  49. cell.style.transitionDuration = '1s'
  50. cell.style.backgroundColor = ''
  51. }
  52. }
  53. //Подсветить строку и столбец
  54. // let cells = document.querySelectorAll('td');
  55. // let rows = document.querySelectorAll('tr');
  56. // for (let cell of cells) {
  57. // cell.onmouseover = function () {
  58. // for (let rowCell of this.parentElement.children) {
  59. // rowCell.style.backgroundColor = '#ccc'
  60. // rowCell.style.color = '#fff'
  61. // }
  62. // for (let row of rows) {
  63. // let columnCell = row.children[this.cellIndex];
  64. // columnCell.style.backgroundColor = '#ccc'
  65. // columnCell.style.color = '#fff'
  66. // }
  67. // cell.style.backgroundColor = '#000'
  68. // cell.style.color = '#fff'
  69. // }
  70. // }
  71. // for (let cell of cells) {
  72. // cell.onmouseout = function () {
  73. // cell.style.backgroundColor = ''
  74. // cell.style.color = ''
  75. // for (let rowCell of this.parentElement.children) {
  76. // rowCell.style.backgroundColor = ''
  77. // rowCell.style.color = ''
  78. // }
  79. // for (let row of rows) {
  80. // let columnCell = row.children[this.cellIndex];
  81. // columnCell.style.backgroundColor = ''
  82. // columnCell.style.color = ''
  83. // }
  84. // }
  85. // }
  86. //Calc
  87. // let calculatorContainer = document.querySelector('.calculator')
  88. // let result = document.createElement('div');
  89. // calc.onclick = function () {
  90. // let age = ageInput.value;
  91. // let normalPressureMax = Math.round(102 + 0.6 * age)
  92. // let normalPressureMin = Math.round(63 + 0.5 * age)
  93. // result.innerText = `Ваше нормальное артериальное давление: ${normalPressureMax} на ${normalPressureMin}`
  94. // calculatorContainer.appendChild(result);
  95. // ageInput.value = '';
  96. // }
  97. //Calc Live
  98. let calculatorContainer = document.querySelector('.calculator')
  99. let result = document.createElement('div');
  100. calculatorContainer.appendChild(result);
  101. let calculate = function() {
  102. let age = ageInput.value;
  103. let normalPressureMax = Math.round(102 + 0.6 * age)
  104. let normalPressureMin = Math.round(63 + 0.5 * age)
  105. result.innerText = `Ваше нормальное артериальное давление: ${normalPressureMax} на ${normalPressureMin}`
  106. if (!ageInput.value) {
  107. result.innerText = ''
  108. }
  109. }
  110. ageInput.oninput = calculate;
  111. let message = document.createElement('div')
  112. message.classList.add('buttonMessage')
  113. message.innerText = 'Отожми обратно!!!'
  114. calculatorContainer.appendChild(message)
  115. calc.onclick = function () {
  116. message.style.display = ''
  117. message.classList.toggle('buttonMessage')
  118. }