- Fork and clone this project.
- Open the
foreclosure.jsfile in your editor. - Run
$ npm installto install all needed packages for this project. - Run
$ npm testrun the tests and have them continually watch for changes and re-run tests automatically. - Follow the instructions below, and every time you see this symbol
an additional test should pass.
Use strict mode for this exercise.
A global variable named data is available to you. This variable is an object.
- Declare a key named steve on the data object, with an value of null.
- Declare a key named stevesLoan on the data object, with an value of null.
- Declare a key named monthsUntilEvicted on the data object, with an initial value of 0.
Declare a function named loan() that takes 0 arguments
Write the following statements inside the loan() function block
- Declare a variable named
accountusing 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
- Declare a function named
missPaymentthat takes0arguments.
- Access the
defaultedproperty of theaccountvariable and increase it's value by1. - Write a conditional that, when the value of
account.defaultedis greater than or equal toaccount.defaultsToForeclose, will run the following statement:- set the value of the
foreclosedproperty of theaccountobject totrue
- set the value of the
- returns a literal object with the following properties:
- key :
getBalance, value : an unnamed function expression that takes0arguments. - key :
receivePayment, value : an unnamed function expression that takes1argument namedamount. - key :
getMonthlyPayment, value : an unnamed function expression that takes0arguments. - key :
isForeclosed, value : an unnamed function expression that takes0arguments.
Declare a function named borrower() that takes 1 argument named loan
Write the following statements inside the borrower() function block
- Declare a variable named
accountusing 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
- returns a literal object with the following properties:
- key :
getFunds, value : an unnamed function expression that takes0arguments. - key :
makePayment, value : an unnamed function expression that takes0arguments.- Conditionally perform either block of statements
- if
account.fundsis greater than the value of the loan's monthly payment - otherwise
- if
- Conditionally perform either block of statements
- key :
payDay, value : an unnamed function expression that takes0arguments.
- Invoke the
loanfunction and assign it's return value to the variabledata.stevesLoan. - Invoke the
borrowerfunction passing in the argumentdata.stevesLoanand assign it's return value to the variabledata.steve. - Create a
whileloop that runs the following statement whiledata.stevesLoanis not foreclosed:
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.
Adjust the while loop to also exit when the house has been paid off.
Copyright (c) 2015 Dev League. Licensed under the MIT license.

