lundi 13 décembre 2021

Random Array Sort Method Javascript

Currently I'm building a quiz app, which displays a verb with a right and 3 wrong answers in a random order. The class is:

class IrregularVerb {
    constructor(verb, right, wrongFirst, wrongSecond, wrongThird) {
        this._verb = verb;
        this._right = right;
        this._wrong = [wrongFirst, wrongSecond, wrongThird];
    }

    randomOrder() {
        return this._wrong.sort(0.5 - Math.random());
    }
}

const irregularVerbList = [
    new IrregularVerb("read", "read", "rode", "ride", "ridden"),
    new IrregularVerb("go", "went", "gone", "got", "god")
]


const randomWrongAnswer = irregularVerbList[randomNumber].randomOrder;

randomWrongAnswer should return an Array with the last 3 object parameters in a random order, but it displays "function randomOrder()". Is the method declaration or its call wrong?




Aucun commentaire:

Enregistrer un commentaire