GithubHelp home page GithubHelp logo

devleague / js-calculator Goto Github PK

View Code? Open in Web Editor NEW
3.0 6.0 204.0 110 KB

an exercise in revealing module pattern

HTML 0.29% CSS 0.99% JavaScript 98.72%
calculator js-calculator exercise javascript revealing-module-pattern module-pattern module

js-calculator's Introduction

Js-Calculator

We will be creating calculators by utilizing the Revealing Module Pattern. Scope also comes into play in this exercise as a way to create functions and variables that are either both privately or publically available.

The CalculatorModule will return an object when invoked. This object will have functions attached to it that perform different operations. Users will not be able to access these functions without first creating a new Calculator.

This calculator will also have private variables: total and memory. Users will not be able to access these values directly. Only the functions will be able to interact with those values, functions like: .add(), .subtract(), .multiply(), .divide(), etc.

NOTE: Make sure you VALIDATE all of your inputs!!

"taco" + 3 //Not valid

Example of usage

var myCalculator = calculatorModule(); // creates a new calculator to be used
myCalculator.load(6); // initial value to be stored in a private variable named `total`
myCalculator.add(5); // adds 5 to `total`
myCalculator.getTotal(); // returns the value of `total`

Getting Started

  1. Fork this repository and clone it from your personal GitHub Account
  2. In the Terminal, navigate to the newly created folder for this repository
  3. Install dependencies by running the command: npm install
  4. Run tests by running the command: npm test
  5. Your work will be one in the file named: calculator.js
  6. Make your tests pass!

References

Front-end Masters' JS fundamentals to functional

Essential Javascript Design Patterns - Module Pattern

js-calculator's People

Contributors

jaywon avatar joekarlsson avatar sgnl avatar souzooka avatar theremix avatar thgaskell avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

js-calculator's Issues

Change exercise to require students to implement IIFE and invoke their own module

Lecture slides show module pattern as an IIFE that's output is stored in a variable but the exercise just has them write a function that the test invokes and then calls methods upon.

We should be consistent and have the students invoke their own module and tests should just run against the global module variable.

Also, may want to add a note to pay attention to the tests to know which methods the module needs to reveal.

Most tests for `add` validator check pass by default

The validator test for the add method passes most cases by default since it's checking for the return value to be a string value.

Examples

1 + ''  // => "1"
1 + []  // => "1"
1 + {}  // => "1[object Object]"
1 + (function () {})  // => "1function () {}"

We might want to fix this by enforcing a specific error string to be returned, or maybe to throw errors?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.