# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
300 lines (282 sloc) 14.2 KB
 One step equation intuition
randRange(1, 6) randRange(A + 1, 10) B - A randFromArray([ [i18n._("Spunky Sam"), "spunky-sam.png"], [i18n._("Mr. Pink"), "mr-pink.png"], [i18n._("Orange Juice Squid"), "orange-juice-squid.png"], [i18n._("Purple Pi"), "purple-pi.png"], [i18n._("Pants"), "mr-pants.png"], [i18n._("Old Spice Man"), "old-spice-man.png"], ])

How much does UNKNOWN weigh?

KhanUtil.scale.onChange = function(leftCoef, a, rightCoef, b) { $("#sub-left").prop("disabled", a === 0);$("#add-left").prop("disabled", a === 10); $("#sub-right").prop("disabled", b === 0);$("#add-right").prop("disabled", b === 10); var leftOp = ""; var rightOp = ""; var leftOpSign = (a - A > 0) ? "+" : "-"; var rightOpSign = (b - B > 0) ? "+" : "-"; $(".desc-a").text(abs(a - A));$(".desc-b").text(abs(b - B)); $("#description1").children().hide();$("#description2").parent().show(); var desc2Text = ""; var desc4Text = ""; if (a - A !== 0 && b - B !== 0) { leftOp = " \\blue{" + leftOpSign + abs(a - A) + "}"; rightOp = " \\green{" + rightOpSign + abs(b - B) + "}" if (a - A < 0 && b - B < 0) { $("#description1 .opt-1").show(); } else if (a - A < 0 && b - B > 0) {$("#description1 .opt-2").show(); } else if (a - A > 0 && b - B < 0) { $("#description1 .opt-3").show(); } else if (a - A > 0 && b - B > 0) {$("#description1 .opt-4").show(); } } else if (a - A !== 0) { leftOp = " \\blue{" + leftOpSign + abs(a - A) + "}"; if (a - A < 0) { $("#description1 .opt-5").show(); } else if (a - A > 0) {$("#description1 .opt-6").show(); } } else if (b - B !== 0) { rightOp = " \\green{" + rightOpSign + abs(b - B) + "}" if (b - B < 0) { $("#description1 .opt-7").show(); } else if (b - B > 0) {$("#description1 .opt-8").show(); } } else { $("#description1 .opt-none").show();$("#description2").parent().hide(); } desc2Text = "\\qquad x + " + A + leftOp + (a - A === b - B ? " \\quad=\\quad " : " \\quad\\neq\\quad ") + B + rightOp; $("#description3").children().hide(); if (a - A === b - B) { if (a - A !== 0) { if (a === 0) {$("#description3 .opt-done").show(); desc4Text = "\\qquad x \\quad=\\quad " + X; } else { $("#description3 .opt-notdone").show(); desc4Text = "\\qquad x + " + a + " \\quad=\\quad " + b; }$("#description3").show() $("#description4").parent().show(); } else {$("#description3").hide() $("#description4").parent().hide(); } } else {$("#description3 .opt-different").show(); $("#description3").show()$("#description4").parent().hide(); } KhanUtil.processMath($("#description2")[0], desc2Text, true); KhanUtil.processMath($("#description4")[0], desc4Text, true); }; // TODO(emily): make this faster (don't re-init every time) KhanUtil.scale.init({ unknown: X, leftConst: A, rightConst: B, image: Khan.imageBase + "avatars/" + AVATAR });

This is algebra?

Yep! We can represent the problem with an equation if we let the letter x represent UNKNOWN's weight:

[ $("input#answer").val(), KhanUtil.scale.leftConst, KhanUtil.scale.rightConst ] if (guess[0] === "") { return ""; } if (guess[1] !== 0) { return i18n._("Make sure %(name)s is alone on " + "one side of the scale.", {name: UNKNOWN}); } if (guess[1] + X !== guess[2]) { return i18n._("Make sure the scale is balanced."); } return +guess[0] === X; KhanUtil.scale.setLeftWeight(guess[1]); KhanUtil.scale.setRightWeight(guess[2]);$("input#answer").val(guess[0]);