Question: Basically I'm building an iOS app which allows users to track their moods throughout the month so that they can evaluate when they are most stressed and when they are most happy.

Each day, users can write a block of information about the day and colour code each day so that in a list view they can quickly see how the month is going (for example, if most of the month is red then it indicates that they are having a bad month).

I am using green, amber, and red to identify the moods of users. But I'm having trouble making each individual cell the colour that the user has selected. I have given each colour cell a tag to identify the user's choice. I'm just having trouble actually calling the function to allow it to be displayed on the screen. 

This is the code in my list view controller:

```
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!

    let post = posts[indexPath.row]

    let cellTitle = cell.viewWithTag(1) as! UILabel
    cellTitle.text = post.title

    let cellText = cell.viewWithTag(2) as! UILabel
    cellText.text = post.text

    return cell
}

```

I know that I need to call the functions, but how do I do this?

Answer: 
As I have already commented, you will have to loop over array and compute html and set it. Your function `clearAndShow` will set last value only.

I have taken liberty to update your code. You should not save data in different arrays. Its better to use one array with proper constructed object.

[JSFiddle](https://jsfiddle.net/RajeshDixit/s5tqxkyL/)

```js
var data = [];
var titleInput = document.getElementById("title");
var nameInput = document.getElementById("name");
var ticketInput = document.getElementById("tickets");

var messageBox = document.getElementById("display");

function insert() {
  var title, name, ticket;
  title = titleInput.value;
  name = nameInput.value;
  ticket = ticketInput.value;
  data.push({
    title: title,
    name: name,
    ticket: ticket
  });
  clearAndShow();
}

function clearAndShow() {
  // Clear our fields
  titleInput.value = "";
  nameInput.value = "";
  ticketInput.value = "";
  messageBox.innerHTML = computeHTML();
}

function computeHTML() {
  var html = "<table>";
  console.log(data)
  data.forEach(function(item) {
    html += "<tr>";
    html += "<td>" + item.title + "</td>"
    html += "<td>" + item.name + "</td>"
    html += "<td>" + item.ticket + "</td>"
    html += "</tr>";
  });
  html += "</table>"
  return html;
}
```

```css
article,
aside,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<head>
  <script class="jsbin" src=""></script>
  <script class="jsbin" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

  <body>
    <form>
      <h1>Please enter data</h1>
      <input id="title" type="text" placeholder="Title" />
      <input id="name" type="text" placeholder="Name" />
      <input id="tickets" type="text" placeholder="Tickets" />
      <input type="button" value="Save/Show" onclick="insert()" />
    </form>
    <div id="display"></div>
  </body>
```
Please try and change your js code like below, not the most elegant but a start:

```
function clearAndShow () {
  // Clear our fields
  titleInput.value = "";
  nameInput.value = "";
  ticketInput.value = "";

  // Show our output
  messageBox.innerHTML = "";
  messageBox.innerHTML += "<tr>";
  messageBox.innerHTML += "<td>Titles</td>";
  messageBox.innerHTML += "<td>Name</td>";
  messageBox.innerHTML += "<td>Tickets</td>";
  messageBox.innerHTML += "</tr>";
  for(i = 0; i <= titles.length - 1; i++)
  {
    messageBox.innerHTML += "<tr>";
    messageBox.innerHTML += "<td>" + titles[i]+ "</td>";
    messageBox.innerHTML += "<td>" + names[i] + "</td>";
    messageBox.innerHTML += "<td>" + tickets[i]+ "</td>";
    messageBox.innerHTML += "</tr>";
  }
}

```

and your display html like so:

```
<table id="display"></table>

```

have a look at fiddle over here <https://jsfiddle.net/gvanderberg/cwmzyjf4/>

The data array in Rajesh's example is the better option to go for.