Q:

Javascript - How to use variable when writing table

I'm trying to print the value of a variable in the first column of my table, but when I run the method, I get the name of the variable instead
I have the following code

function writeTable() {
  var table;
  var uInput = document.test.input.value;
  table = "<table><tr><th colspan=3>Table Header</th></tr>";
  table += "<tr><th>Column1</th><th>column2</th><th>column3</th></tr>";
  table += '<tr><td>uInput</td><td>Value2</td><td>value3</td></tr>';
  document.write(table);
}
<form name="test">
  <input type="text" name="input">
</form>
<input type="submit" name="submit" value="Write Table" onclick="writeTable()">

A:

You need to change this line:
table += '<tr><td>uInput</td><td>Value2</td><td>value3</td></tr>';

To use template literal:
table += `<tr><td>${uInput}</td><td>Value2</td><td>value3</td></tr>`;

Or standard concatenation
table += '<tr><td>' + uInput + '</td><td>Value2</td><td>value3</td></tr>';

