Javascript AFrame loop error

Hello! I have been creating a funny copy of minecraft called “mine and craft” (not the exact same), and I was trying to make terrain generation with a loop. The script adds a 100 times in random a random spot (with x). But it gives me so many errors with it, and I am wondering why it is doing that.

Here is the code that is making the errors:

var scene = document.getElementById('yesyes'); // the scene in aframe
var grass = '<a-box rotation="-90 0 0" position="' + Math.floor(Math.random() * 100).toString; + ' 0 0" material="src:grass.png" height="1" width="1" repeat="1 1"></a-box>';
function terrainGenerate(){
  for(var a = 0;a < 100; a++){
    scene.innerHTML += grass
  }
}
terrainGenerate()

The full project is here: https://replit.com/@DaxCodes/mine-and-craft

Thanks
- Dax

It should be .toString(), with parentheses

2 Likes

Actually, you don’t have to convert integers before merging them to a string.
So removing the .toString should fix the bug!

2 Likes

ended up not using the terrain generator anyway. the string thing didn’t work either. (and deleted the whole project thing too apparently.)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.