Your js only needs to be:
function add(num) {console.log(num)}
Waiting for dom load doesn't seem relevant as the function is only called after the buttons have become visible to the user.
I have tested it & it runs very nicely.