I'm attempting to shuffle items (cards that have English words) from a flashCards array, so that each card can appear randomly when the user reloads the page. I tried using the Math.floor(Math.random()) function, but it's not working. How can I randomly display cards from an array of cards?
home.page.html:
<ion-content padding>
<app-flash-card *ngFor="let card of flashCards" [ngClass]="randomize()">
<div class="flash-card-front">{{card.front}}</div>
<div class="flash-card-back">{{card.back}}</div>
</app-flash-card>
</ion-content>
home.page.ts:
export class HomePage {
flashCards: any;
constructor(public navCtrl: NavController) {
this.flashCards = [
{back: 'accreditation', front: 'official approval'},
{back: 'AIDA', front: 'Attention, Interest, Desire, Action (Model for advertising effectiveness)'},
{back: 'airtime', front: 'broadcasting time'},
{back: 'ambient noise', front: 'background noise'},
{back: 'ambitious', front: 'ambitious, driven'}
];
};
randomize(){
var index=Math.floor(Math.random()*this.flashCards.length);
return this.flashCards[index];
}
}