Method of Dividing Fractions
Division is the inverse operation of multiplication;
That is exactly what we'll do with for fractions.
Invert the fractions that come after a division sign, as
well change the division sign to multiplication, and then
follow through with multiplication.
Algorithm Steps to Divide Fractions in JavaScript
Say we are to simplify
21/8 ÷ 7/2;
Inverting this will yield
21/8 ÷ 7/2;
Then we can go ahead and multiply.
Create 2 new files; On Notepad++: File, New.
Call them DivideFraction.html and DivideFraction.js;
Type out the adjoining JavaScript code for dividing fractions.
Note: The bulk of the divide_fraction.js code is
a copy of that for multiplying fractions.
So!
Feel free to try out your own set of numerators and denominators for fractional division.
JavaScript code for DivideFraction.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dividing Fractions</title>
<script src="MultiplyFraction.js"></script>
<script src="DivideFraction.js"></script>
</head>
<body>
<h3>Divide Fractions</h3>
<div id="divide_fraction"></div>
<script>
var result = "Solving:<br/>";
for (var i = 0; i < numerators.length-1; i++) {
result += "<sup>" + numerators[i] + "</sup> / <sub>" + denominators[i] + "</sub>";
result += " ; ; ; ;÷ ; ; ; ; ;";
}
result += "<sup>" + numerators[i] + "</sup> / <sub>" + denominators[i] + "</sub><br/><br/>";
maxMember();
doDivide();
result += "Answer  ; ; =  ; ; ";
result += " <sup>" + answer[0] + "</sup> ";
result += "/ <sub>" + answer[1] + "</sub><br/>";
document.getElementById("divide_fraction").innerHTML = result;
</script>
</body>
</html>
DivideFraction.js
numerators = [16, 9, 640, 7];
denominators = [9, 20, 27, 20];
function doDivide() {
var temp;
for (var i = 1; i < numerators.length; i++) {
temp = numerators[i];
numerators[i] = denominators[i];
denominators[i] = temp;
}
doMultiply();
}