So I have this code:
var add, substract, multiply, divide;
var calculation = {
add: {
place: 2,
name: add,
calculation: function (a,b) {return a + b;},
output: function (a,b) {return a + ' + ' + b;},
buttonHTML: '+'
},
substract: {
place: 2,
name: substract,
calculation: function (a,b) {return a - b;},
output: function (a,b) {return a + ' - ' + b;},
buttonHTML: '-'
},
multiply: {
place: 1,
name: multiply,
calculation: function (a,b) {return a * b;},
output: function (a,b) {return a + ' * ' + b;},
buttonHTML: '*'
},
divide: {
place: 1,
name: divide,
calculation: function (a,b) {return a / b;},
output: function (a,b) {return a + ' / ' + b;},
buttonHTML: '/'
},
};
document.getElementById("calculator").innerHTML=('
for (var i = 0;i < 10; i++){
var btn = document.createElement ("BUTTON");
var t = document.createTextNode (i);
btn.appendChild(t);
};');
In my html file the script is loaded in the head elements. In body I have a div element named calculator. Now what I want to do is to create buttons inside of that div element with the loop I have. But what I have written seems to not work and I fail to find any better solution too. Any ideas?
document.getElementById("calculator").innerHTML=part and place the rest of the code inside a function that gets called onwindow.onload.