← Back to challenges

Solve a Linear Equation

JavaScriptHardmathalgebra

Instructions

Create a function that returns the value of x (the "unknown" in the equation). Each equation will be formatted like this:

x + 6 = 12

Examples

solve("x + 43 = 50") ➞ 7

solve("x - 9 = 10") ➞ 19

solve("x + 300 = 100") ➞ -200

Notes

  • "x" will always be in the same place (you will not find an equation like 6 + x = 12).
  • Every equation will include either subtraction (-) or addition (+).
  • "x" may be negative.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Compound Interest