The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Percentage/price script

Hey everyone,

I'm teaching myself a couple of languages this summer and I'm currently learning Javascript. My friend is a CS major in college and he gave me a couple of his assignments to mess around with for fun. I'm working on this percentage/price script right now that I initially thought was really easy, but is currently giving me some trouble. I've successfully created a GUI, but my function isn't working.

The main goal of the project is that the function needs to return a final price based on two given percentages. There are two coffee types - Espresso ($5.99 per unit) and Sumatra ($8.99 per unit). I want to create a script that will allow me to mix the two types of coffee into one unit. The total percentage of this unit, of course, must equal 100%.

On the GUI, one textbox is for the percent Espresso and another is for the percent Sumatra. If the sum of these percents, equals one hundred, then the user can click the "Find Price" button and the final price will be displayed in a textbox below.

I just don't know how to correctly get the function to work. Once the percents are inputted, I want it to check if the sum of the percents equals 100. If it doesn't I want an alert box to pop up. If it does equal 100, I want it to do generate the final price by the formula ((Espresso * 5.99 + Sumatra * 8.99) / 100).