Long Division In Javascript

We are exploring the possibility of developing a workshop to help high-school students solidify their knowledge of core mathematical concepts using a computer to write Javascript code.

The best way for a student to demonstrate and reinforce knowledge of mathematical concepts is to be able to teach them or explain them to another person. We think that teaching mathematical concepts to a computer enables students to do so. We believe that this will both serve as a strong tool for engaging young math students, and provide valuable skills for the workplace.

For example, students could express the algorithms that they use to perform long division with Javascript code. This would provide a means, other than repetition, for students to demonstrate and reinforce their understanding of the mathematical concept.

Implementing the classic long division algorithm in Javascript might look something like this:

function longDivision(n,d){
    var num = n + "",
        numLength = num.length,
        remainder = 0,
        answer = '',
        i = 0;

    while( i < numLength + 3){
        var digit = i < numLength ? parseInt(num[i]) : 0;

        if (i == numLength){
            answer = answer + ".";

        answer = answer + Math.floor((digit + (remainder * 10))/d);
        remainder = (digit + (remainder * 10))%d;
    return parseFloat(answer);


Students could also design their own method for performing long division, and implement it in Javascript the way it makes sense to them. This idea can be applied to all levels of mathematics from multiplication to calculus. We think this approach to learning mathematical concepts is enormously powerful because it teaches students how to construct an algorithm, not just how to use one.

We are not sure if Javascript is the right language to use. Teaching high-school math students concepts like object types is outside the scope of a high-school math class. We are thinking of building some kind of a framework that offers a more palatable syntax and takes care of the details. On the other hand, learning real world Javascript skills could be a great way to engage students.


Contact Us

We'd love to hear from you. Get in touch!


201 South Street, Boston, MA 02111

New York

315 Church St, New York, NY 10013

Phone & Email

(617)379-2752 hello@bocoup.com