Hi rapropos, thanks for this explanation and sorry I did not answer earlier.
I made changes in the app, following your advices from this thread.
But regarding Storage, I do not understand how to use it to store the variable “i” and the cards that have been shuffled. How can I do it based on the file below ? Have you a few example I can follow to achieve that ? thanks
home.ts
import { Component, } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
cards:any = [];
i: number;
constructor(public navCtrl: NavController, private storage: Storage,) {
this.i = 0;
}
ngOnInit() {
this.cards = [
{id: '1', question: 'lkndlkc', answer: 'kdckdlqkn.', hint: 'oidncoisdnc.'},
{id: '2', question: 'bla', answer: 'xnqspin', hint: 'xnsin'},
{id: '3', question: 'csnd', answer: 'xnqcksjd cjspin', hint: 'xnsij dljn'},
{id: '4', question: 'bqlksncla', answer: 'xnqscljqs cpin', hint: 'xnscqns ljin'},
{id: '5', question: 'blalqjsx', answer: 'xnlqjsnxqspin', hint: 'xnsqlksnxin'},
{id: '6', question: 'blq lksnxqsna', answer: 'knk', hint: 'xklnknsin'},
];
console.log(this.cards);
}
setI() {
this.i++;
console.log(this.i)
}
shuffleCards(cards) {
var currentIndex = cards.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = cards[currentIndex];
cards[currentIndex] = cards[randomIndex];
cards[randomIndex] = temporaryValue;
};
console.log(this.cards);
console.log(this.cards[1]);
}
}