Giter Club home page Giter Club logo

foreclosure's Introduction

Foreclosure

Closure Exercise

  1. Fork and clone this project.
  2. Open the foreclosure.js file in your editor.
  3. Run $ npm install to install all needed packages for this project.
  4. Run $ npm test run the tests and have them continually watch for changes and re-run tests automatically.
  5. Follow the instructions below, and every time you see this symbol Test an additional test should pass.

Strict Mode

Use strict mode for this exercise. Test

Initialize variables

A global variable named data is available to you. This variable is an object.

  1. Declare a key named steve on the data object, with an value of null. Test
  2. Declare a key named stevesLoan on the data object, with an value of null. Test
  3. Declare a key named monthsUntilEvicted on the data object, with an initial value of 0. Test

loan()

Declare a function named loan() that takes 0 arguments Test

Write the following statements inside the loan() function block

  1. Declare a variable named account using const, with an initial value being a literal object having the following properties and values:
  • key : borrowed, value : 550000
  • key : balance, value : 286000
  • key : monthlyPayment, value : 1700
  • key : defaulted, value : 0
  • key : defaultsToForeclose, value : 5
  • key : foreclosed, value : false
  1. Declare a function named missPayment that takes 0 arguments.
  • Access the defaulted property of the account variable and increase it's value by 1.
  • Write a conditional that, when the value of account.defaulted is greater than or equal to account.defaultsToForeclose, will run the following statement:
    • set the value of the foreclosed property of the account object to true
  1. returns a literal object with the following properties:
  • key : getBalance, value : an unnamed function expression that takes 0 arguments. Test
    • Create a closure by returning the value of balance by accessing that property of the locally scoped variable account. Test
  • key : receivePayment, value : an unnamed function expression that takes 1 argument named amount. Test
    • Create a conditional statement that will run the following statements when amount is less than account.monthlyPayment :
      • invoke the missPayment function with 0 arguments
    • Finally, decrement the value of the balance property of the account variable, by the value of the amount parameter. Test
  • key : getMonthlyPayment, value : an unnamed function expression that takes 0 arguments. Test
    • Create a closure by returning the value of monthlyPayment by accessing that property of the locally scoped variable account. Test
  • key : isForeclosed, value : an unnamed function expression that takes 0 arguments. Test
    • Create a closure by returning the value of foreclosed by accessing that property of the locally scoped variable account. Test

borrower()

Declare a function named borrower() that takes 1 argument named loan Test

Write the following statements inside the borrower() function block

  1. Declare a variable named account using const, with an initial value being a literal object having the following properties and values:
  • key : monthlyIncome, value : 1350
  • key : funds, value : 2800
  • key : loan, value : loan
  1. returns a literal object with the following properties:
  • key : getFunds, value : an unnamed function expression that takes 0 arguments. Test
    • Create a closure by returning the value of funds by accessing that property of the locally scoped variable account. Test
  • key : makePayment, value : an unnamed function expression that takes 0 arguments. Test
    • Conditionally perform either block of statements
      • if account.funds is greater than the value of the loan's monthly payment
        • decrement account.funds by the value of the loan's monthly payment
        • invoke the loan's receivePayment function, and pass in the value of the loan's monthly payment Test
      • otherwise
        • invoke the loan's receivePayment function, and pass in the value of the account's current funds
        • set the value of the funds property of account to 0 Test
  • key : payDay, value : an unnamed function expression that takes 0 arguments. Test
    • Increase the value of the funds property of account by the value of the property monthlyIncome of account Test

Set variables and "step forward in time"

  1. Invoke the loan function and assign it's return value to the variable data.stevesLoan. Test
  2. Invoke the borrower function passing in the argument data.stevesLoan and assign it's return value to the variable data.steve. Test
  3. Create a while loop that runs the following statement while data.stevesLoan is not foreclosed:
  • data.steve invokes payDay
  • data.steve invokes makePayment
  • increment data.monthsUntilEvicted by 1 Test

Conclusion

All tests should be passing. The value of monthsUntilEvicted should be 13. You can tweak some of hardcoded private values such as loan account.monthlyPayment and borrower account.monthlyIncome a little to inspect the different possible outcomes. however, be careful! if the house never goes into foreclosure, you will encounter an endless loop.

Bonus

Adjust the while loop to also exit when the house has been paid off.

License

Copyright (c) 2015 Dev League. Licensed under the MIT license.

foreclosure's People

Contributors

jaywon avatar jocelynsaysrawr avatar joekarlsson avatar sgnl avatar taesup avatar theremix avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

foreclosure's Issues

Linter needs to be updated to be ES6 Friendly

Since we are starting to use ES6 earlier in the course, it would be a good idea to update the linters so that they are ES6 friendly. The gulpfile in this project uses an old version of jshint that isn't aware of current ES6 code.

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.