Simple Module Example

In this example below you will see how to do a Simple Module Example with some HTML / CSS and Javascript

"Create a module with one private and one public method, the public method can accept any number of arguments. It must disregard any arguments that are not an integer. This method must rely on a private method to calculate the sum of these integers"

Thumbnail
This awesome code was written by gbabula, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright gbabula ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Simple Module Example</title>
  
  
  
  
  
</head>

<body>

  <!--

  "Create a module with one private and one public method, the public method can accept any number of arguments. It must disregard any arguments that are not an integer. This method must rely on a private method to calculate the sum of these integers"

-->
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/gbabula/simple-module-example-vuLaq */
/*

  Simple Module Example
  By: Greg Babula

*/


'use strict';


var MyModule = (function() {
    function calculateSum() {
        var total = 0,
            args = arguments[0],
            argLength = args.length;
        
        for (var i = 0; i < argLength; i++) {
            if (typeof args[i] === "number") {
                total += args[i];
            }
        }
        
        console.log(total);
    };
    
    function getSum() {
        calculateSum(arguments);
    };
    
    return {
        getSum: getSum
    }
}());


// calculate
MyModule.getSum(5, 10, 'x', 'd', 2);

Comments