javascript - How do I display a number before the equations? -
how modify code when equations printed, number displayed before them. example,
2x+1=12
-x+2=5
this code needed modify.
function getrandomnumber(min, max, notthese) { num = min + math.floor((max - min + 1) * math.random()); return (num); } function getoption(s, ch, num) { var = s.split(ch) return a[num - 1]; } function getequation() { var num1 = getrandomnumber(20, -20, ""); var num2 = getrandomnumber(20, -20, ""); var num3 = getrandomnumber(20, -20, ""); var num4 = getrandomnumber(20, -20, ""); var letter = getoption("x,y,z,w", ",", getrandomnumber(1, 4)); var str = "" + num1 + "" + letter + "+" + num2 + "=" + num3 + "" + letter + "+" + num4 + "" var total = (num4 - num2) / (num1 - num3); return (str + " (" + total + ")"); } (var = 1; <= 20; i++) { document.write(getequation() + "<br>") }
add iterator i
document.write(getequation()+"<br>")
function getrandomnumber(min, max, notthese) { num = min + math.floor((max - min + 1) * math.random()); return (num); } function getoption(s, ch, num) { var = s.split(ch) return a[num - 1]; } function getequation() { var num1 = getrandomnumber(20, -20, ""); var num2 = getrandomnumber(20, -20, ""); var num3 = getrandomnumber(20, -20, ""); var num4 = getrandomnumber(20, -20, ""); var letter = getoption("x,y,z,w", ",", getrandomnumber(1, 4)); var str = "" + num1 + "" + letter + "+" + num2 + "=" + num3 + "" + letter + "+" + num4 + "" var total = (num4 - num2) / (num1 - num3); return (str + " (" + total + ")"); } (var = 1; <= 20; i++) { document.write("<span>" + + ": </span>" + getequation() + "<br />") }
body { font: 12px arial; } span { color: red }
Comments
Post a Comment