lundi 10 octobre 2016

Random index doesn't return random value in array

Working on pulling random strings, numbers from an array. When I don't store it in a new variable it works fine. Random strings will pop up on my console log.

var randomBodyParts = ["arm", "leg" , "head", "eye"]; 

randomBodyParts[Math.floor(Math.random() * 3)];

However, when I store it in a new variable, it only returns one repeating string.

var randombodyPart = randomBodyParts[Math.floor(Math.random() * 3)];

Why?




Aucun commentaire:

Enregistrer un commentaire