1 Replies - 819 Views - Last Post: 06 December 2012 - 09:00 AM

#1 Chenardizzle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-November 12

Monthly Balance calculator is too hard...

Posted 06 December 2012 - 08:49 AM

I'm trying to get a monthly balance calculator to work, but I'm completely lost.
I have the html code and cascading style sheet all working together, but my javascripting is where I completely fall apart.
This is what I have so far:
var $ = function(id) { return document.getElementById(id); }
	//--Variables--//
var deposits = 0;
var withdrawls = 0;
var runningBalance = 2000;

var add_trans = function () {
	
	var amount = parseInt( $("amount").value );

		$("deposits").value = ""
		if ( isNaN(amount) || amount <= 0 || amount == null ) {
			alert ("You must input more than $0.01 to make a deposit.");
		} else if ( amount >= 0 ) {
			deposits++;
			runningBalance += amount;
		}
			
		window.onload = function(){
	$("add_trans").onclick = add_trans;
	}
}


I know from listening to people talk about it that I need to have an array of arrays and a bunch of functions, but as I'm completely new to this most of what they say goes well over my head. Can anyone help me make sense of this, please?

Is This A Good Question/Topic? 0
  • +

Replies To: Monthly Balance calculator is too hard...

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3383
  • View blog
  • Posts: 9,573
  • Joined: 08-June 10

Re: Monthly Balance calculator is too hard...

Posted 06 December 2012 - 09:00 AM

first of all, lines #19 - #21 belong outside the function body.

and yes, it might not be a bad idea to store the balance (and related data into an object.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1