main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //1task
  2. const table = document.createElement('table');
  3. for (let i = 0; i <= 9; i++){
  4. let tr = document.createElement('tr');
  5. for (let j = 0; j <= 9; j++){
  6. let td = document.createElement('td');
  7. td.style.border = "1px solid gray"
  8. td.style.padding = "7px"
  9. let val = i * j;
  10. if (val === 0) {
  11. val = i || j;
  12. }
  13. td.innerHTML = val;
  14. tr.append(td);
  15. }
  16. table.append(tr);
  17. }
  18. document.body.append(table);
  19. let tdSelect = document.querySelectorAll('td');
  20. let trSelect = document.querySelectorAll('tr');
  21. tdSelect.forEach(function(td){
  22. td.addEventListener('mouseover', function(event) {
  23. let target = event.target;
  24. target.style.backgroundColor = 'lightblue';
  25. target.parentElement.style.backgroundColor = 'lightblue';
  26. let index = target.cellIndex;
  27. trSelect.forEach (tr => tr.children[index].style.backgroundColor = 'lightblue');
  28. })
  29. td.addEventListener('mouseout', function(event) {
  30. let target = event.target;
  31. target.style.backgroundColor = '';
  32. target.parentElement.style.backgroundColor = '';
  33. let index = target.cellIndex;
  34. trSelect.forEach (tr => tr.children[index].style.backgroundColor = '');
  35. })
  36. });
  37. //2task
  38. // const body = document.body
  39. // const form = document.createElement("form")
  40. // body.append(form)
  41. // form.style.marginTop = "30px"
  42. // let inputOil = document.createElement('input')
  43. // let inputDistance = document.createElement('input')
  44. // let inputButton = document.createElement('input')
  45. // let result = document.createElement('div')
  46. // let span = document.createElement('span')
  47. // let p = document.createElement('p')
  48. // inputOil.id = "inputOil"
  49. // inputDistance.id = "inputDistance"
  50. // inputButton.id = "calc"
  51. // form.append(inputOil)
  52. // form.append(inputDistance)
  53. // form.append(inputButton)
  54. // form.append(result)
  55. // result.append(p)
  56. // result.append(span)
  57. // inputOil.type = "number"
  58. // inputDistance.type = "number"
  59. // inputButton.type = "button"
  60. // inputOil.placeholder = "Введите количество израсходованного топлива"
  61. // inputDistance.placeholder = "Введите дистанцию , которую вы проехали"
  62. // calc.value = "Расчитать расход"
  63. // p.innerText = "Расход составляет:"
  64. // inputOil.style.width = "310px"
  65. // inputOil.style.marginRight = "10px"
  66. // inputDistance.style.width = "300px"
  67. // inputDistance.style.marginRight = "20px"
  68. // result.style.marginTop = "30px"
  69. // calc.onclick = function () {
  70. // let resultFinish = (inputOil.value/inputDistance.value) * 100 + "л. бензина на 100км";
  71. // span.style.color = "red";
  72. // span.innerHTML = resultFinish
  73. // }
  74. //3task
  75. const body = document.body
  76. const form = document.createElement("form")
  77. body.append(form)
  78. form.style.marginTop = "30px"
  79. let inputOil = document.createElement('input')
  80. let inputDistance = document.createElement('input')
  81. let result = document.createElement('input')
  82. inputOil.id = "inputOil"
  83. inputDistance.id = "inputDistance"
  84. result.id = "calc"
  85. form.append(inputOil)
  86. form.append(inputDistance)
  87. form.append(result)
  88. inputOil.type = "number"
  89. inputDistance.type = "number"
  90. result.type = "number"
  91. inputOil.placeholder = "Введите количество израсходованного топлива"
  92. inputDistance.placeholder = "Введите дистанцию , которую вы проехали"
  93. inputOil.style.width = "310px"
  94. inputOil.style.marginRight = "10px"
  95. inputDistance.style.width = "300px"
  96. inputDistance.style.marginRight = "20px"
  97. result.style.marginTop = "30px"
  98. calc.onclick = function () {
  99. let resultFinish = (inputOil.value/inputDistance.value) * 100 + "л. бензина на 100км";
  100. span.style.color = "red";
  101. span.innerHTML = resultFinish
  102. }
  103. function calc() {
  104. result.value = (inputOil.value) / (inputDistance.value) * 100
  105. }
  106. inputOil.oninput = calc
  107. inputDistance.oninput = calc