I have the following array:
var cartasViradas=[
'assets/img/1.png',
'assets/img/2.png',
'assets/img/3.png',
'assets/img/4.png',
'assets/img/5.png',
'assets/img/6.png',
'assets/img/7.png',
'assets/img/8.png',
'assets/img/9.png',
'assets/img/10.png'
];
And I would like to know how I can randomly get one of these array values within a variable.
When I try to use the floor
and random
method in an Ionic 2 .ts extension file, I get the following error:
Uncaught ReferenceError: floor is not defined
This is the code that is causing the error:
var selecionado = [];
for (var i = 0; i < 10; i++) { // Escolha aleatoriamente um da matriz cartasViradas
var randomInd = floor(random(cartasViradas.length));
var face = cartasViradas[randomInd];
selecionado.push(face);
selecionado.push(face);
cartasViradas.splice(randomInd, 1);
}