Heyo! Nice idea you got there. So… I did what you asked for, but i also optimized your code a lot since there was a lot easier way of doing what you did. So here is the link and a screenshot of the code, now you can easily change the width or height of the tilemap and it will not break - it will acually fill the whole thing. Instead of using a sprite like you did, I opted for using a variable to signify the row and change that to create the tiles. And for how i did the thing where it fills the dirt below, I just loop through the grass tiles, and see how much space is left below. Then I just fill it all with dirt and voilla: terrain.
If you have any questions or need further help just ask!
Here, I tidied up a little and made a player you can control so you can look around. Also made it so that all of the blocks are now walls and made the tilemap wider and taller