script2.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // For Select Option
  2. // Используя заготовку выше, создайте выпадающий список с валютами. Элементы выпадающего списка создаются
  3. // с помощью тэга <option>
  4. for_select_option: {
  5. const currencies = ["USD", "EUR", "GBP", "UAH"];
  6. let str = "<select>";
  7. for (let currency of currencies) {
  8. str += `<option value='${currency}'>${currency}</option>`;
  9. }
  10. str += "</select>";
  11. document.write(str); //document.write отобразит ваш HTML на странице
  12. }
  13. // For Table Horizontal
  14. // Аналогично, добейтесь вывода имен в ячейки таблицы по горизонтали (одна строка с четырьмя ячейками)
  15. for_table_horizontal: {
  16. const names = ["John", "Paul", "George", "Ringo"];
  17. let str = "<table><tr>";
  18. for (let name of names) {
  19. str += `<td>${name}</td>`;
  20. }
  21. str += "</tr></table>";
  22. document.write(str); //document.write отобразит ваш HTML на странице
  23. }
  24. // For Table Vertical
  25. // Аналогично, добейтесь вывода имен в ячейки таблицы по вертикали(одна колонка с четырьмя строками,
  26. // в каждой строке - одна ячейка)
  27. for_table_vertical: {
  28. const names = ["John", "Paul", "George", "Ringo"];
  29. let str = "<table>";
  30. for (let name of names) {
  31. str += `<tr><td>${name}</td></tr>`;
  32. }
  33. str += "</table>";
  34. document.write(str); //document.write отобразит ваш HTML на странице
  35. }
  36. // For Table Letters
  37. // Используя заготовку выше, создайте таблицу 3x4. В каждой строке по три ячейки с буквами, четыре строки,
  38. // так как 4 валюты в массиве.
  39. for_table_letters: {
  40. const currencies = ["USD", "EUR", "GBP", "UAH"];
  41. let str = "<table style = 'border-collapse: collapse; border: 1px solid; width: 100px; height: 120px; text-align: center'>";
  42. for (let currency of currencies) { //цикл создает строки
  43. //одна итерация цикла создает ОДНУ СТРОКУ
  44. str += "<tr>";
  45. console.log(currency);
  46. for (let letter of currency) { //цикл создает ЯЧЕЙКИ в ОДНОЙ СТРОКЕ
  47. //одна итерация цикла создает ОДНУ ЯЧЕЙКУ
  48. str += `<td style = 'border-collapse: collapse; border: 1px solid'>${letter}</td>`;
  49. console.log(letter);
  50. }
  51. str += "</tr>";
  52. }
  53. str += "</table>";
  54. document.write(str); //document.write отобразит ваш HTML на странице
  55. }
  56. // For Multiply Table
  57. // Выведите таблицу умножения 5x5 из задания Multiply table в таблицу, используя вложенные for .... of и
  58. // document.write. Сделайте черезстрочную подсветку - задавайте четным строкам один цвет фона, нечетным - другой
  59. for_multiply_table: {
  60. const arr = [
  61. [0, 0, 0, 0, 0],
  62. [0, 1, 2, 3, 4],
  63. [0, 2, 4, 6, 8],
  64. [0, 3, 6, 9, 12],
  65. [0, 4, 8, 12, 16]];
  66. let str = "<table style = 'border-collapse: collapse; border: 1px solid; text-align: center; margin-top: 20px;'>";
  67. for (let index of arr.keys()) {
  68. if (index % 2 == 0) {
  69. str += "<tr style='background-color: #babfc4;'>";
  70. } else {
  71. str += "<tr style='background-color: #fcb450;'>";
  72. }
  73. for (let number of arr[index]) {
  74. str += `<td style = 'border-collapse: collapse; border: 1px solid; width: 30px; height: 30px;'>${number}</td>`;
  75. }
  76. str += "</tr>";
  77. }
  78. str += "</table>";
  79. document.write(str);
  80. }
  81. // Reduce HTML
  82. // Реализуйте задачу For Select Option используя reduce:
  83. reduce_html: {
  84. const currencies = ["USD", "EUR", "GBP", "UAH"];
  85. let str = "<select>";
  86. str += currencies.reduce((a, b) => `${a}<option value='${b}'>${b}</option>`, "");
  87. str += "</select>";
  88. document.write(str);
  89. }