www.webdeveloper.com
Results 1 to 4 of 4

Thread: One must start from somewhere....

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Question One must start from somewhere....

    Hi, I'm learning JS, and I need help. Here is my code:
    Code:
    //This object is going to be used
    //so that at the end of the calcCost function,
    //the client can see the subtotal, tax, and grandtotal
    //in a portion of the webpage. Like a console, mayhaps.
    var dataWindow=new Object();
    dataWindow.height=80;
    dataWindow.width=500;
    //This is the function that takes the subtotal, tax and grandtotal and simply displays them in 
    //the data window.
    dataWindow.showResults=function(subtotal,tax,grandtotal){
    	return "Subtotal" + subtotal;
    	return "Tax" + tax;
    	return "Grandtotal" + grandtotal;
    }
    //This is the function that calculates the subtotal, tax and grandtotal.
    function calcCost(){
    var itemCost=prompt("Enter the cost of the item here.");
    	var subtotal=itemCost;
    		document.write("Subtotal" + subtotal);
    	var tax=.0825;
    		document.write("Tax Charge" + tax);
    	var grandtotal=(subtotal*tax);
    		document.write("Grand Total" + grandtotal);
    	dataWindow.showResults();//this call of the function should take the   subtotal,tax and grandtotal
    	//and display them in the dataWindow.
    }
    I truly appreciate the help, and realize this is probably the stupidest code you've all laid eyes on. I apologize, but one must start from SOMEWHERE.

  2. #2
    Join Date
    Mar 2012
    Posts
    202
    Code:
    function calcCost() {
    var cost = prompt("Enter the cost of the item here.");
    var tax = 0.0825;
    alert("Subtotal: "+cost+"\nTax Charge: "+(cost*tax)+"\nGrand Total: "+((1+tax)*cost)); }
    Is that what you were looking for?

  3. #3
    Join Date
    Jul 2012
    Posts
    3
    the
    Code:
    function calcCost
    isn't what I had the problem with, its the
    Code:
    dataWindow
    object. I made the object because i wanted to be able to have it dynamically update with the subtotal,grandtotal and tax parameters.

  4. #4
    Join Date
    Mar 2012
    Posts
    202
    You may want to look into the uses of "window.showModalDialog"

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