I would like to create an on click button to run a javascript function to generate a grid in the style of a crossword.
I have written some javascript to create the grid and I have made the button with the onclick function, but I am unable to get the button to run the script.
I'm sure the solution is glaringly obvious but I'm new to coding so any and all help would be appreciated!
<html>
<body>
<!--<button onclick="generateGrid()">Click to generate crossword grid</button>-->
<div id="crosswordGrid" align="center"></div>
</body>
</html>
function generateGrid () {
var crosswordGrid = document.getElementById("crosswordGrid");
for (var r = 0; r < rows; r++) {
var row = crosswordGrid.appendChild(document.createElement("div"));
for (var c = 0; c < cols; c++) {
row.appendChild(document.createElement("span"));
}
}
const gridSize = 7;
var rows = gridSize;
var cols = gridSize;
}
This is what my current code looks like; http://jsfiddle.net/YEJ9A/97/