- Fork and clone this project.
- Open the
foreclosure.js
file in your editor. - Run
$ npm install
to install all needed packages for this project. - Run
$ npm test
run 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
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
- Declare a function named
missPayment
that takes0
arguments.
- Access the
defaulted
property of theaccount
variable and increase it's value by1
. - Write a conditional that, when the value of
account.defaulted
is greater than or equal toaccount.defaultsToForeclose
, will run the following statement:- set the value of the
foreclosed
property of theaccount
object totrue
- set the value of the
- returns a literal object with the following properties:
- key :
getBalance
, value : an unnamed function expression that takes0
arguments. - key :
receivePayment
, value : an unnamed function expression that takes1
argument namedamount
. - key :
getMonthlyPayment
, value : an unnamed function expression that takes0
arguments. - key :
isForeclosed
, value : an unnamed function expression that takes0
arguments.
Declare a function named borrower()
that takes 1
argument named loan
Write the following statements inside the borrower()
function block
- 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
- returns a literal object with the following properties:
- key :
getFunds
, value : an unnamed function expression that takes0
arguments. - key :
makePayment
, value : an unnamed function expression that takes0
arguments.- Conditionally perform either block of statements
- if
account.funds
is 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 takes0
arguments.
- Invoke the
loan
function and assign it's return value to the variabledata.stevesLoan
. - Invoke the
borrower
function passing in the argumentdata.stevesLoan
and assign it's return value to the variabledata.steve
. - Create a
while
loop that runs the following statement whiledata.stevesLoan
is 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.