Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Can you help me with this bank account js?

THIS IS THE INDEX

<!DOCTYPE html>
<html>
  <head>
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css">
    <link href="css/styles.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.12.0.js"></script>
    <script src="js/scripts.js"></script>
    <title>Bank Account</title>
  </head>
  <body>
    <div class="container">
      <h1>Sign up for your bank account</h1>

      <div class="row">
        <div class="col-md-6">
          <h2>Please enter your information</h2>
          <form id="Info">
            <div class="form-group">
              <label for="new-name">Name</label>
              <input type="text" class="form-control" id="new-name">
            </div>
            <div class="form-group">
              <label for="new-initialdeposit">Initial deposit</label>
              <input type="number" class="form-control" id="new-initialdeposit">
            </div>

            <button type="submit" class="btn">Your Account</button>
          </form>

          <form id="movements">
            <div class="form-group">
              <label for="new-deposit">Deposit</label>
              <input type="number" class="form-control" id="new-deposit">
            </div>
            <div class="form-group">
              <label for="new-withdraw">Withdrawal</label>
              <input type="number" class="form-control" id="new-withdraw">
            </div>

            <button type="submit" class="submit">Your Balance</button>
          </form>



          <h2>Balance</h2>
          <ul id="balance">

          </ul>
        </div>


      </div>
      </div>```
THIS IS THE JS

```//business logic
function Balance(name,initialdeposit) {
  this.name = name;
  this.initialdeposit = initialdeposit;
}



Balance.prototype.fullCalc= function(deposit, withdraw,balance) {
  this.deposit= deposit;
  this.withdraw= withdraw;
  this.balance= balance

  if(this.inititialdeposit===0){
    return "Youre broke"
  }else if (this.initialdeposit>0){
  balance= this.initialdeposit + this.deposit - this.withdraw;
}
return balance

}

function resetFields() {
$("input#new-name").val("");
$("input#new-initialdeposit").val("");
$("input#new-deposit").val("");
$("input#new-withdraw").val("");
}

// user interface logic
$(document).ready(function() {
  $("form#Info").submit(function(event) {
    event.preventDefault();

    var inputtedName = $("input#new-name").val();
    var inputtedInitialDeposit = $("input#new-initialdeposit").val();
    var newAccount = new Balance(inputtedName,inputtedInitialDeposit);
    $("ul#balance").append("<li><span class='balance'>" + newAccount.name + " " + newAccount.initialdeposit + "</span></li>")
      $( "#movements").show();

});
});
      $("#movements").submit(function(event) {
        event.preventDefault();
          var inputtedDeposit = $("input#new-deposit").val();
          var inputtedWithdraw = $("input#new-withdraw").val();
          var finalBalance = new Finalbalance(inputtedDeposit, inputtedWithdraw);
            $("ul#balance").append("<li><span class='balance'>" + finalBalance.balance + "</span></li>");


resetFields();

});

Thank you!!

2 Answers

Steven Parker
Steven Parker
243,656 Points

You didn't say what kind of issue you are having, but I noticed that the movements submit handler includes a call to Finalbalance.

:point_right: However, Finalbalance is not defined.

If that's not it, try explaining your issue.

The problem is that the first form works good. It appends the user name and the initial balance. However, when you enter the amounts of deposit and withdrawal it doesnt process the formula and doesnt append the results.