usingMaths.com
From Theory to Practice - Math You Can Use.







<< PreviousNext >>

JavaScript Program to Calculate HCF (GCD) with User Input - Kids Fun Project



Understanding the HCF Algorithm in JavaScript

This JavaScript program calculates the HCF (Highest Common Factor) using user input and the Fast HCF JavaScript Code from the previous lesson.
Let's add some input mechanism so our user enters the set of numbers whose H.C.F. (G.C.D.) we are to find.


Combining the H.C.F. (G.C.D.) JavaScript Code and Collecting User Input

The code follows the same steps as that from the previous lessons.
We just adapted the HCF.html

How to use the HCF Code in JavaScript

The user gets to enter his/her choice of numbers for the HCF JavaScript algorithm.
After entering each number, the user clicks the Next Number! button to enter his/her number.
After the user enters his/her last number, with the last number still in the text box, the user clicks the Find H.C.F. button.

Create 1 new file; On Notepad++: File, New.
Call them HCFInput.html
Type out the adjoining JavaScript code for collecting input for H.C.F. (G.C.D.).


So! JavaScript Fun Practice Exercise - Find HCF with User Input

As a fun practice exercise, feel free to try out your own numbers, and see how the JavaScript code finds the HCF of your input numbers.









<< PreviousNext >>