Change this to 

    require(tableCols == $num, "Table only has " + tableCols + " columns, expecting $num")

Also, do you actually want tableCols to be publicly accessible?