Q:

HTML5 Local storage cannot find variable even though console.log reveals it

I am using a sample script to populate a table in my website. Basically I want to copy save a persons answers persistently so if they refresh the page, their choices are still there. I have the function adding items to the table, the clear all button works, the main problem is the delete button will not work. I get the error; "can't find variable" in console, even though I can see the variable stored by checking console.log(window.localStorage); 
window.addEventListener("load",updateTable,false);

function updateTable() {
    var tbody = document.getElementById("output");
    while (tbody.getElementsByTagName("tr").length > 0) {
    tbody.deleteRow(0);
    }
    var row;
    if (localStorage.length==0) {
        row = tbody.insertRow(i);
        cell = row.insertCell(0);
        cell.colSpan="4";
        cell.innerHTML = "Nothing to Show";
    }
    for (var i=0; i < localStorage.length; ++i) {
        row = tbody.insertRow(i);
        cell = row.insertCell(0);
        cell.innerHTML = i;
        cell = row.insertCell(1);
        cell.innerHTML = localStorage.key(i)
        cell = row.insertCell(2);
        cell.innerHTML = localStorage.getItem(localStorage.key(i));
        cell = row.insertCell(3);
        cell.innerHTML = '<button class="btn btn-danger btn-sm" onclick="deleteItem('+localStorage.key(i)+');"><i class="fa fa-trash-o"></i> Delete</button>';
    }
}
function deleteItem(key) {
    if (!confirm("Are you sure you want to delete this item?")) return;
    localStorage.removeItem(key);
    updateTable();
}

function clearStorage() {
    if (!confirm("Are you sure you want to delete all local storage for this domain?"))     return;
    localStorage.clear();
    updateTable();
}

function save() {
    var key = document.getElementById("key").value;
    var value = document.getElementById("value").value;
    localStorage.setItem(key,value);
    updateTable();
}

A:

You've not delimited the key in the delete call...
cell.innerHTML = '<button class="btn btn-danger btn-sm" onclick="deleteItem(\''+localStorage.key(i)+'\');"><i class="fa fa-trash-o"></i> Delete</button>';

Notice I added the quotes around the key.  Try that and see if it helps :)

