-4

is anyone able to tell me what i am doing wrong? The problem is that "ramdom1" is not being added to the array.(nothing is showing up in the text_loot)

Any help would be great, thanks.

var lootArray = [].join("<br>");

lootArray.add("ramdom1");

document.getElementById("text_loot").innerHTML = lootArray;

3 Answers3

3

First, the method to add element to array is called push, not add

Second, when you do join on array, you get string, which doesn't have methods like push or add

If you really want to do this, you need this code:

var lootArray = []

lootArray.push("ramdom1");

lootArray = lootArray.join("<br>");

document.getElementById("text_loot").innerHTML = lootArray;
Nikolai Mavrenkov
  • 1,851
  • 18
  • 21
2

Replace

lootArray.add("ramdom1");

with

lootArray.push("ramdom1");
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

use push method like this. hope it will works

lootArray.push("ramdom1"); 
Asad
  • 3,070
  • 7
  • 23
  • 61