HTML + Javascript will be needed to implemt this. For this problem, you will mai
ID: 3680431 • Letter: H
Question
HTML + Javascript will be needed to implemt this.
For this problem, you will maintain an associative array whose keys are people's names. An associated value is an object with three properties: deposits (an array of the person's deposits), withdrawals (an array of the person's withdrawals), and balance (the person's current balance). We assume that an account starts out with a zero balance so that the current balance is the sum of the deposits minus the sum of the withdrawals. Write an HTML document prob2.html that loads a JavaScript file prob2. is. When the body is finishes loading, function go () is called. The body of the document consists of an empty div element with id value "recs". Function go () in prob2. js first calls function init (), which prompts for names until the user clicks Cancel. Each name becomes a key in an associative array, and the associated value is an object with its deposits and withdrawals properties initialized to (), and its balance property initialized to 0. It returns this associative array, which is assigned to, say, recs in go (). Function go() next calls update(), passing it recs. This function loops through round after round as long as the user clicks OK (not Cancel) in the confirmation box asking about another round. In each round, the function loops over all the names of people. For each person, it asks for their deposit and their withdrawal for that round. The user enters "0" if no deposit or no withdrawal was made. As long as the deposit is not "0", it is added to the end of the array that is the value of the deposits property, similarly, the withdrawal is added to withdrawals. (An easy way to add something to the end of an array is to use the array's push () method. If is an array and x is some value, are push(x) adds x to the end of or, increasing its length by 1.) The person's balance is also updated each round. Finally, go() calls out Recs (), passing it recs. This function assigns to, say, recs Ref a reference to the div element (with id recs"). Its constructs in, say, recs string with all the information in associative array recs, and this string is assigned to the inner HTML property of recs Ref. For each element of recs, the string has one line with the name followed by a The next three lines have, respectively, the array of deposits, the array of withdrawals, and the balance for the person named. Each of these three lines begins with two spaces. (Use the character entity reference & to have the browser insert a space.) Use the to string () method of the arrays of deposits and withdrawals to get a quick string representation of the contents of these arrays; do not spend time on appearances. (The contents of these arrays will be strings that have not been converted to numbers. These strings are converted to numbers when the balance is updated since that involves subtraction.) The screenshot at right shows the output w hen names "Al" and "lid" were supplied, and the update went through two rounds. In the first round, Al deposited 5.50 and withdrew 3.20 while Ed deposited 3.00 and withdrew nothing. In the second round, Al deposited 5.20 and withdrew 4.10 while Ed neither deposited nor withdrew.Explanation / Answer
---------------------------prob2.html---------------------------------
<!DOCTYPE html>
<html>
<head>
<script src="prob2.js"></script>
<script></script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="dep"></div>
</body>
</html>
--------------------------------------------------
-------------------------prob2.js-------------------------
var names=[],deposits=[],balance=[],withdrawls=[];
var i=0,j=0;
function go()
{
init();
deposit();
withdraw();
depo();
}
function init()
{
var nm=true;
while(nm)
{
nm=prompt("enter "+(i+1)+" name");
names.push(nm);
i++;
}
}
function deposit()
{
alert("names were Done now deposits");
var dp;
j=0;
i=names.length;
while(j<i-1)
{
dp=prompt("enter "+names[j]+" 's deposit");
deposits.push(dp);
j++;
}
}
function withdraw()
{
j=0;
var wd;
alert("deposits were Done now withdraws");
while(j<i-1)
{
wd=prompt("enter "+names[j]+" 's withdraws");
withdrawls.push(wd);
j++;
}
}
function depo()
{
j=0;
while(j<i-1)
{
document.getElementById("dep").innerHTML=(document.getElementById("dep").innerHTML)+"<br>Name:"+names[j]+"<br>Deposits:"+deposits[j]+"<br>Withdraws:"+withdrawls[j]+"<br>Balance:"+(deposits[j]-withdrawls[j])+"<br><br>";
j++;
}
}
-----------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.