# 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:

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

It can be rewritten shorter:

`let 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:

`let div = document.querySelector('#elem'); let table = createTable(3, 4); table.style.color = 'red'; div.appendChild(table);`

Modify your `createTable` function as described in theory.

Suppose we have such a div with paragraphs:

`<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.

←→
↑
en ru