www.webdeveloper.com
Results 1 to 3 of 3

Thread: help with javascript calculation

Threaded View

  1. #1
    Join Date
    Apr 2014
    Posts
    2

    help with javascript calculation

    Hello, I am having trouble with a script im working on. I am trying to get two inputs from a user via the prompt box as integers. Once the numbers reach over a hundred they should get an alert box. The problem is that it does the calculations wrong and I don't know what I'm doing wrong. Thank you!

    For a clearer explanation, this is my assignment:


    7.12 Develop a script that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
    a) Account number
    b) Balance at the beginning of the month
    c) Total of all items charged by this customer this month
    d) Total of all credits applied to this customer's account this month
    e) Allowed credit limit
    The script should input each of these facts from a prompt dialog as an integer, calculate the new balance (= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For customers whose credit limit is exceeded, the script should output HTML5 text that displays the message "Credit limit exceeded."


    THIS IS MY HTML:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset = "utf-8">
    <title>
    </title>
    <script src="712.js"></script>
    </head>
    
    <body onLoad="checkBalance()">
    <p>Your purchase amounts</p>
    <ol id="charges">
    </ol>
    <br>
    <!-- <p>Your refund amounts</p>
    <ol id="refunds">
    </ol> -->
    </body>
    </html>

    THIS IS MY JAVASCRIPT
    Code:
    var accountActivity = [];//this is the charges and debits to the account
    
    
    function checkBalance()
    
    {
    
    	alert('hello, my name is omid nassir. welcome to my program. please click okay to continue');
    
    	var firstName = prompt('what is your first name?');
    	var lastName = prompt('what is your last name?');
    	var fullName = firstName + " " + lastName;
    
    
    	alert('Hello ' + fullName + '. Please enter the charges and refunds for your shopping this month, please click okay to continue');
    
    	var count = 0;
    	var total = 100;
    	while(count<total)
    	{
    		var charge = prompt('please enter charge');
    		var cost = parseInt(charge, 10);
    		accountActivity.push(cost);
    
    		var credit = -prompt('please enter refund');
    		var refund = parseInt(credit, 10);
    		accountActivity.push(refund);	
    		count = (count + cost) - refund;
    		document.write(count);
    		
    	
    if(count >total)
    
    	alert(fullName + ' you are spending too much!');
    document.getElementById('charges').innerHTML = "<li>" + accountActivity.join("</li><li>") + "</li>";
    }
    
    
    }
    Last edited by jedaisoul; 04-16-2014 at 03:37 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles