mercredi 2 octobre 2019

Adding Random Variables to Questions in Javascript

In this question, I am looking for something "inline" instead of calling a function as below.

I have a multiple choice game with about a 1000 math questions such as "3 + 4 = ?" and "What is (sqrt(2)^(4)". These are stored in a question file (not xml)

How can I modify the questions so that every time the first question is called, it uses a random variable between (1,20). So instead of 3 + 4 = ? , it asks Random(1,20) + Random(1,20) = ?

I'm writing a function for every single question but I'm wondering if there is a better method.

function Question001(){
        var x = rInt(1, 5);
        var y = rInt(6, 15);
        question.textContent = qCount + " " + "What is " + x +" + " + y +" ?" ;          
    }

thanks!




Aucun commentaire:

Enregistrer un commentaire