Finished function generateGrid