UNPKG

random-calculations

Version:

Simple library for arithmetic operations

40 lines (29 loc) 853 B
function math(){ var op = ["*", "+", "-"][Math.floor(Math.random()*3)]; if(op !== '*'){ var b = Math.floor(Math.random() * 100) +1; var a = Math.floor(Math.random() * 10) + b; }else{ var b = Math.floor(Math.random() * 10) +1; var a = Math.floor(Math.random() * 10) +1; }; function convertOption(option) { var result; var options = { '*':"×",'/':'÷','-':'-','+':'+'}; result = options[op]; return result; }; let question = a + " " + convertOption(op) + " " + b , answer = eval( a + op + b); return {question, answer} }; const {answer, question} = math() const arabicrize = (str) => str.replace(/\d/g, (digit) => '٠١٢٣٤٥٦٧٨٩'[digit]); const ar = arabicrize(answer.toString()) module.exports ={ question, answer, ar };