← Back to challenges

Neatly Formatted Math

JavaScriptHardstringsformattingmath

Instructions

Given a simple math expression as a string, neatly format it as an equation.

Examples

formatMath("3 + 4") ➞ "3 + 4 = 7"

formatMath("3 - 2") ➞ "3 - 2 = 1"

formatMath("4 x 5") ➞ "4 x 5 = 20"

formatMath("6 / 3") ➞ "6 / 3 = 2"

Notes

  • You will need to deal with addition, subtraction, multiplication and division.
  • Division will have whole number answers (and will obviously not involve 0).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Fractions and Rounding