# 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,
i = 0;

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

if (i == numLength){
}

remainder = (digit + (remainder * 10))%d;
i++;
}
}

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.

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

1. I think that the idea is to use a real-world programming language in the hopes that students that are turned off by too much abstraction might find this to be more engaging, and also that it will help get kids into learning actual practical programming skills. If this is ineffective / impossible, though, then definitely using Javascript is crazy and something like SETL (I’ve done a lot of Mathematica work myself) would be more appropriate.

When you say \”we\”, who are you referring to? I’d love to check out your work.

2. Thanks for the algorithm. I implemented it in 140 characters of Javascript. Here is the complete implementation code and example of 1/9998: https://www.dwitter.net/d/1
Note that this simple division results in Powers of Two: 0001, 0002, 0004, 0008, 0016, 0032, 0064….
Try to change 9998 for 9997 and you will see Powers of Three (1, 3, 9, 27, 81…). Guess what 9996 does?
I have discovered a truly remarkable demonstration of this result, but this comment is too small to contain.