Skip To Main Content

Long Division In Javascript

Posted by Boaz Sender

Mar 06 2010

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;
        i++;
    }
    return parseFloat(answer);
}

longDivision(356,8);

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.

Posted by
Boaz Sender
on March 6th, 2010

Comments

We moved off of Disqus for data privacy and consent concerns, and are currently searching for a new commenting tool.

Contact Us

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