Js achieves random four arithmetic questions, and js four arithmetic questions
This article mainly introduces four random arithmetic questions, so that 30 random arithmetic questions can be automatically generated. Four random computing questions can be generated for primary school students, but the problem persists! They do not know negative numbers or decimal places. Therefore, the condition must be added. The Code is as follows:
switch(Arr[n]){ case "+":{ sum=a+b; break; } case "-":{ sum=a-b; while(sum<0){ var a = GetRandomNum(1,30); var b = GetRandomNum(1,30); sum=a-b; } break; } case "*":{ sum=a*b; break; } case "/":{ sum=a/b; while(hasDot(sum)){ var a = GetRandomNum(1,100); var b = GetRandomNum(1,100); sum=a/b; } break; }
In this way, both the negative number and the decimal number are lost.
However, elementary school students seem to calculate scores. So I started to try writing scores again.
<Body> <button class = "btn-success btn-sm" type = 'click' onclick = "pl_f () "> start generating question </button> <span id =" text_f "> </span> <script> function GetRandomNum (Min, Max) {var Range = Max-Min; var Rand = Math. random (); return (Min + Math. round (Rand * Range);} function max_num (x, y) {var t; while (y) {t = x % y; x = y; y = t ;} return x;} function fenshu (a, B, p) {if (p = 1) {if (a> B) {return a + "/" + B ;} else if (a <B) {return a + "/" + B;} else {return 1 ;}} else {var x = a/p; var y = B/p; if (y = 1) {return x;} else {return x + "/" + y ;}} function pl_f () {var son_a = GetRandomNum (); var par_ B = GetRandomNum (); var son_c = GetRandomNum (); var par_d = GetRandomNum ); var X = son_a + "/" + par_ B; var Y = son_c + "/" + par_d; document. write ("first score:" + X + "<br>"); document. write ("second score" + Y + "<br>"); max_x = max_num (son_a, par_ B); max_y = max_num (son_c, par_d); document. write ("the first maximum common divisor" + max_x + "<br>"); document. write ("the second maximum common divisor" + max_y + "<br>"); var N = fenshu (son_a, par_ B, max_x); var M = fenshu (son_c, par_d, max_y); document. write ("first score simplification:" + N + "<br>"); document. write ("second score simplification" + M) ;}</script> </body>
This can dynamically generate two scores, and then output the maximum approximate number of the score numerator and denominator. The simplest form of output molecules.
The last step is to put the score together in an integer!
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head> <title> new document </title> <meta http-equiv =" Content-Type "content =" text/html; charset = UTF-8 "> <meta name =" generator "content =" editplus "/> <meta name =" author "content =" "/> <meta name =" keywords "content = ""/> <meta name = "description" content = ""/>
This is the case after the program is executed.
The last version separated from the question!
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head> <title> new document </title> <meta http-equiv =" Content-Type "content =" text/html; charset = UTF-8 "> <meta name =" generator "content =" editplus "/> <meta name =" author "content =" "/> <meta name =" keywords "content = ""/> <meta name = "description" content = ""/>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.