I'm trying to add arrays into onclick button for my simple JavaScript calculator.
My first try was that process(text[i]); in the code but it doesn't work at all.
So, I converted the array item to string and gave to the onclick function. then it runs a strange way.
Would you let me know how I can pass to correct type?
var text = ["+", "-", "*", "/", "SQRT", "POW", "RNDM", "MAX", "MIN"];
for (var i = 0; i < text.length; i++) {
var child = document.createElement('button');
child.innerText = text[i];
child.value = text[i];
var temp = text[i].toString(); //<-- convert to make sure it is string
child.onclick = function () {
process(temp); //<-- it doesn't work properly, and it won't accept "process(text[i])???".
}
label1.appendChild(child);
}
document.body.appendChild(label1);