Index.js imports the function from larger.js.
2 random whole numbers are then passed to the imported function.
Finally, the larger number is then displayed in the console.
As example, if 5 and 8 are used, the console will display “8 is the larger number”. Must use module to export and import the function that finds the larger number.
Here is the solution to implement a module file (could be called larger.js) has a function that finds the larger of two numbers.
Step 1: Create a new file name larger.js.
Then Create the find larger number function in larger.js as below-
Step 2: Now go to index.js.
And import the findLargerNumber function from larger.js from the index.js file.
Furthermore, complete the remaining code as shown below.
Finally, you can see the output on the console, Please see on the right-hand side of the above snapshot. Where it says –
2 numbers are: 82 7 82 is the larger number.
Note: By using // at the beginning of line 7. You can comment out the “console.log(“2 number are:”, num1 ,num2);” if you don’t need to display it on the console.