I'm trying to solve this problem. First step is create a table after clicking on first button. Later the table is creating and one row has another button which should starting another function play() with arguments. For this example I just want to display ready in console but this is undefined. When I call this function by simply console.log outside the function then is working correctly. What is wrong with calling function play by button?
<table class="table">
<tr>
<th>Team A</th>
<th>Team B</th>
<th></th>
</tr>
</table>
<button onclick="create()">Create next Match</button>
const table = document.querySelector('.table');
const teams=[{
name: 'Real',
point: 10
},
{
name: 'Barca',
point: 20
}]
function create(){
table.innerHTML += `
<tr id="r1m1">
<td id="host">${teams[0].name}</td>
<td id="guest">${teams[1].name}</td>
<td id="host_score"></td>
<td id="guest_score"></td>
<td><button onclick="play(${teams[0]},${teams[1]})">Play</button></td>
</tr>`
}
function play(a,b){
console.log("ready");
}
console.log(play(teams[0],teams[1]))
[Object object].