# Khan/khan-exercises

Rewrite "Writing expressions 1"

Summary: Based on Jesse's spec.

Reviewers: eater

Reviewed By: eater

Differential Revision: http://phabricator.khanacademy.org/D859
1 parent b325159 commit 9bbb4bce1482160e95992ccbae103a36c67c47db spicyj committed Oct 22, 2012
Showing with 77 additions and 39 deletions.
1. +77 −39 exercises/writing_expressions_1.html
116 exercises/writing_expressions_1.html
 @@ -1,65 +1,103 @@ - + Writing expressions 1
-
- (random() > 0.5 ? -1 : 1) * (rand(9) + 1) - (random() > 0.5 ? -1 : 1) * (rand(9) + 1) -
-
+
+ randRange(1, 4) + -randRange(1, 10) + + + (M === 1 ? "1?" : M === -1 ? + "[-\\u2212]\\s*1?" : + (M < 0 ? "[-\\u2212]\\s*" + (-M) : M)) + + "\\s*(?:\\*\\s*)?x" + + + B < 0 ? + "[-\\u2212]\\s*" + (-B) : + "" + B + + + X_TERM_RE + + (B < 0 ? "\\s*" : "\\s*\\+\\s*") + + C_TERM_RE + + + C_TERM_RE + + (M < 0 ? "\\s*" : "\\s*\\+\\s*") + + X_TERM_RE + + + B === 0 ? + "^" + X_TERM_RE + "$" : + "^(?:" + X_C_RE + "|" + C_X_RE + ")$" + +
-

Select the expression that matches the following phrase:

+

Write an expression to represent:

-

The sum of B and the product of A and x.

-

expr(["+", ["*", A, "x"], B])

-
-
• expr(["+", ["*", -A, "x"], B])
• -
• expr(["+", ["*", A, "x"], -B])
• -
• expr(["+", ["*", B, "x"], A])
• -
• expr(["+", ["*", -B, "x"], -A])
• -
-
-

What is the product of A and x?

-

What is the sum of B and expr(["*", A, "x"])?

+

Cardinal(-B) less than twicecardinal(M) times a number x.

+

RE

+
+

TwiceCardinal(M) times a number x can be written as Mx.

+

Cardinal(-B) less than something means that we subtract -B from it.

+

If we subtract -B from expr(["*", M, "x"]), we have expr(["+", ["*", M, "x"], B]).

-

Take the quantity A times x, and then add B.

-
-

What is the quantity of A times x?

-

+
+ randRange(1, 4) + randRange(1, 10) +
+

Cardinal(B) more than twicecardinal(M) times a number x.

+
+

TwiceCardinal(M) times a number x can be written as Mx.

+

Cardinal(B) more than something means that we add B to it.

+

If we add B to expr(["*", M, "x"]), we have expr(["+", B, ["*", M, "x"]]).

-

B plus the product of A and x.

-
-

What is the product of A and x?

-

What is B plus expr(["*", A, "x"])?

+
+ -randRange(1, 4) + randRange(1, 10) +
+

Cardinal(B) minus twicecardinal(-M) times a number x.

+
+

TwiceCardinal(-M) times a number x can be written as -Mx.

+

Cardinal(B) minus something means that we subtract it from B.

+

If we subtract expr(["*", -M, "x"]) from B, we have expr(["+", B, ["*", M, "x"]]).

-

The sum of B and the quantity A times x.

-
-

What is the quantity A times x?

-

What is the sum of B and expr(["*", A, "x"])?

+
+ randRange(2, 4) + 0 +
+

The product of cardinal(M) and a number x.

+
+

"Product" means that we multiply M and x.

+

If we multiply M and x, we have expr(["*", M, "x"]). +

+
+
+
+ randRange(1, 4) + randRange(1, 10) +
+

The sum of cardinal(B) and twicecardinal(M) times a number x.

+
+

TwiceCardinal(M) times a number x can be written as Mx.

+

"Sum" means that we add B and expr(["*", M, "x"]).

+

If we add B and expr(["*", M, "x"]), we have expr(["+", B, ["*", M, "x"]]).

-
- -
-

Let's break this problem into smaller and easier pieces.

-

-

A \times x = \color{orange}{expr(["*", A, "x"])}

-

-

Ax{} + B

-

So, the original phrase can be written as expr(["+", ["*", A, "x"], B]).