Skill: one-two-step-equations
One- & Two-Step Equation Solver
Type any one- or two-step equation — the solver shows each inverse operation on both sides.
Solve a one- or two-step equation
Handles x+b=c, x−b=c, ax=c, x/a=c, ax±b=c, x/a±b=c, a−x=c, −x+b=c — with integers.
Check a proposed solution
Substitutes your value into the equation and reports whether both sides match.
(function(){ 'use strict'; var btns = document.querySelectorAll('.tabbtn'); btns.forEach(function(b){ b.addEventListener('click', function(){ btns.forEach(function(x){ x.classList.remove('active'); }); document.querySelectorAll('.panel').forEach(function(p){ p.classList.remove('active'); }); b.classList.add('active'); document.getElementById(b.getAttribute('data-tab')).classList.add('active'); }); }); })();
// __PURE_BEGIN__
var TOOL_API = (function(){
'use strict';
function N(s){ s = String(s).trim(); if (!/^[+-]?\d+$/.test(s)) return null; return parseInt(s, 10); }
/* parse bounded one/two-step forms -> {a,b,c} meaning a*x + b = c, or null */
function parseEq(eq){
var s = String(eq).replace(/\s+/g, '').toLowerCase().replace(/×/g, '*');
var parts = s.split('=');
if (parts.length !== 2) return null;
var L = parts[0], R = N(parts[1]);
if (R === null) return null;
var m;
m = /^x([+-])(\d+)$/.exec(L);
if (m) return {a:1, b:m[1] === '+' ? N(m[2]) : -N(m[2]), c:R, form:'x+b'};
m = /^([+-]?\d+)x$/.exec(L);
if (m){ var a = N(m[1]); if (a === 0) return null; return {a:a, b:0, c:R, form:'ax'}; }
m = /^x\/(\d+)$/.exec(L);
if (m){ var d = N(m[1]); if (d === 0) return null; return {a:1, b:0, c:R, form:'x/a', div:d}; }
m = /^([+-]?\d+)x([+-])(\d+)$/.exec(L);
if (m){ var a2 = N(m[1]); if (a2 === 0) return null; return {a:a2, b:m[2] === '+' ? N(m[3]) : -N(m[3]), c:R, form:'ax+b'}; }
m = /^x\/(\d+)([+-])(\d+)$/.exec(L);
if (m){ var d2 = N(m[1]); if (d2 === 0) return null; return {a:1, b:m[2] === '+' ? N(m[3]) : -N(m[3]), c:R, form:'x/a+b', div:d2}; }
m = /^([+-]?\d+)-x$/.exec(L);
if (m) return {a:-1, b:N(m[1]), c:R, form:'a-x'};
m = /^-x([+-])(\d+)$/.exec(L);
if (m) return {a:-1, b:m[1] === '+' ? N(m[2]) : -N(m[2]), c:R, form:'-x+b'};
return null;
}
function solve(eqStr){
var p = parseEq(eqStr);
if (!p) return {ok:false, error:'Could not read that. Try a form like 2x+3=11 or x/4+2=5.'};
var a = p.a, b = p.b, c = p.c, steps = [];
if (p.form === 'ax'){
steps.push('Divide both sides by ' + a + ': x = ' + c + ' ÷ (' + a + ').');
} else if (p.form === 'x/a'){
steps.push('Multiply both sides by ' + p.div + ': x = ' + c + ' × ' + p.div + '.');
return {ok:true, x:c * p.div, steps:steps};
} else if (p.form === 'x+b'){
steps.push((b >= 0 ? 'Subtract ' + b : 'Add ' + (-b)) + ' from both sides: x = ' + c + (b >= 0 ? ' − ' + b : ' + ' + (-b)) + '.');
} else if (p.form === 'a-x'){
steps.push('Add x to both sides: ' + b + ' = ' + c + ' + x.');
steps.push('Subtract ' + c + ' from both sides: x = ' + (b - c) + '.');
return {ok:true, x:b - c, steps:steps};
} else {
/* two-step: undo b first, then a */
steps.push((b >= 0 ? 'Subtract ' + b : 'Add ' + (-b)) + ' from both sides: ' +
(a === 1 ? 'x' : a === -1 ? '−x' : a + 'x') + ' = ' + (c - b) + '.');
if (p.form === 'x/a+b'){
steps.push('Multiply both sides by ' + p.div + ': x = ' + (c - b) + ' × ' + p.div + '.');
return {ok:true, x:(c - b) * p.div, steps:steps};
}
steps.push('Divide both sides by ' + a + ': x = ' + (c - b) + ' ÷ (' + a + ').');
}
var x = (c - b) / a;
if (x !== Math.round(x)) return {ok:false, error:'That equation has a non-integer solution (' + x + '). This solver handles integer solutions.'};
return {ok:true, x:x, steps:steps};
}
function checkSol(eqStr, xStr){
var p = parseEq(eqStr);
if (!p) return {ok:false, error:'Could not read the equation. Try a form like 2x+3=11.'};
var x = N(xStr);
if (x === null) return {ok:false, error:'Enter an integer for x.'};
var lhs;
if (p.form === 'x/a') lhs = x / p.div;
else if (p.form === 'x/a+b') lhs = x / p.div + p.b;
else lhs = p.a * x + p.b;
var good = Math.abs(lhs - p.c) < 1e-9;
return {ok:true, good:good, x:x, lhs:lhs, c:p.c,
steps:['Substitute x = ' + x + ': left side = ' + lhs + ', right side = ' + p.c + '.',
good ? 'Both sides match — x = ' + x + ' is a solution.' : 'They differ — x = ' + x + ' is NOT a solution.']};
}
return {parseEq:parseEq, solve:solve, checkSol:checkSol};
})();
// __PURE_END__
(function(){ 'use strict'; function $(id){ return document.getElementById(id); } function esc(s){ return String(s).replace(/\x26/g,'&').replace(//g,'>'); } document.addEventListener('DOMContentLoaded', function(){ $('calcS').addEventListener('click', function(){ var r = TOOL_API.solve($('eq').value); var err = $('errS'), res = $('resS'); err.classList.remove('show'); res.classList.remove('show'); if (!r.ok){ err.textContent = r.error; err.classList.add('show'); return; } $('ansS').innerHTML = 'x = ' + esc(String(r.x)) + ''; $('stepsS').innerHTML = r.steps.map(function(s){ return '
'; }).join(''); res.classList.add('show'); }); $('calcC').addEventListener('click', function(){ var r = TOOL_API.checkSol($('ceq').value, $('cx').value); var err = $('errC'), res = $('resC'); err.classList.remove('show'); res.classList.remove('show'); if (!r.ok){ err.textContent = r.error; err.classList.add('show'); return; } $('ansC').innerHTML = r.good ? 'Yes — it checks out.' : 'No — it does not satisfy the equation.'; $('stepsC').innerHTML = r.steps.map(function(s){ return '
'; }).join(''); res.classList.add('show'); }); }); })();