mardi 7 mars 2017

I need another way to code this using arrays and a random generator

The purpose of this codes is to create an array of one hundred block objects randomly selected but I'm not sure if this code will work

var array_result = ();

for( let i= 0; i<100; i++){
  var number=  parseInt (7* Math.Random());
  switch (number) {
    case 0:
      array_result.push (new Dirt ());
      break;
    case 1:
      array_result.push (new CobbleStone ());
      break;
    case 2:
      array_result.push (new sand ());
      break;
    case 3:
      array_result.push (new IronOre ());
      break;
    case 4:
      array_result.push (new Gravel ());
      break;
    case 5:
      array_result.push (new Coal ());
      break;
    case 6:
      array_result.push (new RedStone ());
      break;
    case 7:
      array_result.push (new CraftingTable ());
      break;
  }
}

console.log(array_result)

Aucun commentaire:

Enregistrer un commentaire