Returning a table from a function in JavaScript

In the previous lesson, we made the createTable function. Let's modify this function so that it does not add a table to some element, but simply returns it via return.

That is, the above code of the previous lesson is converted into this:

javascriptlet div = document.querySelector('#elem');
let table = createTable(3, 4);
div.appendChild(table);

It can be rewritten shorter:

javascriptlet div = document.querySelector('#elem');
div.appendChild(createTable(3, 4));

Getting a reference to the table may be needed in order to do something with the created table. For example, let's color its text color red:

javascriptlet div = document.querySelector('#elem');

let table = createTable(3, 4);
table.style.color = 'red';

div.appendChild(table);
Задание 1

Modify your createTable function as described in theory.

Задание 2

Suppose we have such a div with paragraphs:

html<div id="elem">
  <p>1</p>
  <p>2</p>
  <p>3</p>
</div>

Use the createTable function to create a new table and then insert it at the end of the div.