[Javascript] Math

Ben Curtis Quixote at LaMancha.org
Thu Aug 16 11:24:33 CDT 2001


> have a form text field where the user can enter the Quantity
> (myForm.Quantity). Here's the kicker. The client says $2 a ticket, 3 for $5.
> 
> Ok, so 10 tickets is $17. 10 divided by three is 3.33333etc. 3 times 5 is
> 15, plus the $2 for the other ticket.
> 
> But how do you put this in a script calculation?

function tixPrice(Qty) {
    var Discounted = parseInt(Qty /3) *5;
    var RegPrice   = (parseInt(Qty) %3) *2;
    return (Discounted + RegPrice);
}

--
+Ben Curtis

"On the other side of the screen, it all looks so easy."









More information about the Javascript mailing list