usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< Previous Next >>

Code for Multiplying Fractions in JavaScript



Method of Multiplying Fractions

Multiplying fractions is pretty straightforward:
Cancel out all common factors between numerators and denominators, then multiply whatever is left numerator to numerator and denominator to denominator.



Algorithm Steps to Multiply Fractions in JavaScript:

If we have
                  4/9 x 21/8;

Step 1:

Find any common factor between any numerator and any denominator.

Step 2:

Cancel out any such common factor.

= X7
421
98
3 
Step 3:

Repeat Steps 1 & 2 recursively until there are no more common factors.

=1X 
47
38
 2
=7
6

Create 2 new files; On Notepad++: File, New.
Call them MultiplyFraction.html and MultiplyFraction.js;
Type out the adjoining JavaScript code for multiplying fractions.



So!

Feel free to try out your own set of numerators and denominators for fractional multiplication.









<< Previous Next >>