people\'s 1 (10 pts.). For this problem, you will maintain an associative array
ID: 3873853 • Letter: P
Question
people's 1 (10 pts.). For this problem, you will maintain an associative array whose keys are custName. An associated value is an object with three properties: accounts (an array of a customer's current salary) and loans (an array of a customer's loan objects). We assume that a customer's salary can start out with a zero rite an HTML document probl.html that loads a JavaScript file prob1.js. When the body is finishes loading, function go ) is called. The body of the document consists of an empty div element with id value "custs' Function go) in prob1.js first calls function customer, which prompts for the customer's name. Each name becomes a key in an associative array, custs, and the associated value is an object with its accounts property initialized to [], loan property initialized to [] the address property initialized to an empty string and its salary property initialized to 0 Remember that the accounts property is an object with several properties, therefore a function account is needed. This method should prompt the user for th balance as account associative pair and then adds the account object to the array. The account ) should prompt the user for more accounts until the user clicks Cancel. The customer () should continuously prompting the user more customers until the user clicks Cancel. You are limited to using Savings and Checking accounts name. Function go ) next calls approveLoan ). This function prompts the user for a name a of customer that needs a loan then the name of the loan and the loan amount0.0). If the name of the customer is not in the associative array for the customer, the user should be re-prompt saying user does not exist. Otherwise, approaveLoan ) should loop through all the customer's accounts for the account balances, each account balance should be added to customer's salary then compared to the loan amount. If the loan amount is 3 times less than the salary + account balances, then approve the loan, otherwise disapprove the loan. The approaveLoan ) should continuously prompting the user more names until the user clicks Cancel. You should store the approved/disapproved. Special situation, if the customer already has any loans, loop through the loan array and add the loan amounts for that customer. Use the approved loans + the salary + total account balances to determine if the new loan should be approved or not Finally, go ) calls outcusts, passing it custs. This function assigns to, say custsRef a reference to the div element (with id " custs"). Its constructs in, say, custsstr a string with all the information in associative array custs, and this string is assigned to the innerHTML property of custsRef. For each element of custs, the string has one line with the name followed by a ":'. The AccSaing-S50000.00, Checking $0.0 next four lines have, respectively, the address, the salary, Loan:Car-18000.00-Approved, House-$20000.00-Disapproved the array of accounts, the array of loans. Each of these four Jan: lines begins with two spaces. (Use the character entity reference to have the browser insert a space.) Use the tostring) method of the arrays of accounts and Loans: C Jill: Address: GreensboroExplanation / Answer
<!DOCTYPE html>
<html>
<body>
<p id="demo">Hi.</p>
<script>
document.getElementById("custs").innerHTML = custstr[0] + “ : “ + “address” + custstr[1]+ "account type:” + custstr[2]+ “salary:” + custstr[3]+ ”loan:8000”;
Function go(custname)
{
myObject.customer(custname);
approveloan(custname);
outcusts(custs(custname));
}
Custs(custname)
{
Var custstr= [“Jill”, “Greensboro”, “saving”, “20000”,
}
var myObject = {
accounts: 0,
address: “ ”,
loans: “”,
salary: 0,
customer: function (custname) {
return this.accounts(custname) + " " + this.address + “ “ +this.loans + “ “ +this. salary;
}
}
function accounts(acctname){
Return this.acctname + “ “ + this.balance;
}
Function approveloan(loanname,loanamount)
{
for(i=0; i<arguments.length;i++)
{
If(custname==acctname)
{
Balance+=this.salary;
}
}
If(3*loanamount<balance)
{
Return “loanamount: “ + this.loanamount + “loan approved”
}
Else
Return “loanamount: “ + this.loanamount + “loan disapproved”
}
</script>
Go();
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.