Hello there are three files:

CW.html with code:

<html> <head> <meta charset = "utf-8"> <title>Таблиця имен</title> <script>src = "tablescript.js"</script> </head> <body></body> </html> 

tablestyle.css with code:

  table { width: 50%; border: 3px solid black; border-collapse: collapse; margin: auto; } td, th { padding: 2px; border: solid black; } th { background: deepskyblue; } .center { text-align: center; } tbody tr:hover { background: cyan; } 

and tablescript with code:

 function randomValue(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function tableMaker() { amount = +prompt("Ввеите кол-во полей:"); var wnd = window.open('#','_blank'); wnd.document.write ('<html>'); wnd.document.write ('<head>'); wnd.document.write ('<title></title>'); wnd.document.write ('<link rel = "stylesheet" type = "text/css" href= "tablestyle.css">'); wnd.document.write ('</head>'); wnd.document.write ('<body>'); wnd.document.write ('<p align = "center" style = "font-size: 30px">Таблица персональных даных </p>'); wnd.document.write ('<table>'); wnd.document.writeln('<tr> <th>№<\/th><th>Ф.И.О.<\/th><th>Год рождения<\/th><th>Вес<\/th> <\/tr>'); for (var i = 0; i < amount; i++) { var name = prompt("Введите Ф.И.О." + (i + 1) +" - го человека:"); if (name.trim() == "") { do { name = prompt("Вы ничего не ввели. Попробуйте, еще раз:") } while (name.trim() == ""); } wnd.document.writeln('<tr class = "center">'); wnd.document.writeln('<td>' + (i + 1) + '<\/td>'); wnd.document.writeln('<td>' + name + '<\/td>'); wnd.document.writeln('<td>' + randomValue(1900, 2016) + '<\/td>'); wnd.document.writeln('<td>' + randomValue(3, 150) + '<\/td>'); wnd.document.writeln('<\/tr>'); } wnd.document.write ('</table>'); wnd.document.write ('</body>'); wnd.document.write ('</html>'); } 

This is my first work with javascript and css, please tell me what is wrong.

  • What's wrong with that? - D-side
  • Doesn't work at all - Muscled Boy
  • rather nothing shows - Muscled Boy
  • This is all because src is an attribute that should be, not an inside - Grundy
  • but there are no errors in the console - Muscled Boy

2 answers 2

Need to fix two points:

 <html> <head> <meta charset = "utf-8"> <title>Таблиця имен</title> <!-- Первая правка --> <script src="tablescript.js"></script> </head> <!-- Вторая правка --> <body onload="tableMaker()"> </body> </html> 

  • onload not required. It is enough just to call. - Qwertiy
  • why not do this? - Muscled Boy
  • the code works with it - Muscled Boy
  • Not fundamentally, it is important to just call the function. It is possible to bind to a button or to other logic. - AkaInq
  • @AkaInq, thank you for your attention - Muscled Boy

You need to insert 2 simple lines in the head block:

 <link href="dir/tablestyle" rel="stylesheet"> //Отвечает за присоединение файла css <script src="tablescript.js"></script> //Отвечает за присоединение файла js 

dir is responsible for the file path relative to your index file.

  • The css file in this case is added from javascript and is used in a new window from which it will not be available. on this css do not need to add. - AkaInq