How to properly end a javascript statement?

Please help with this code, its a simple problem im sure, prompt box not showing in if else statement?

  • im just about at my witts end with this, i just need the prompt to come up, which it doesnt, it does when i place it outside the if else statement, i just need the stupid thing to show up when i put it in the actual statement so it can get the data and run the function. i know its the if else statement, i just cant seem to find whats wrong with it! Help Please! --------- <html> <head> <title>Wage calculator </title> <head> </head> <body> here <script language="JavaScript" type="text/javascript"> function calculate() { var hrwork = parseFloat(prompt ("How many hours did you work?","")) var payrate = parseFloat(prompt("Please enter your payrate","")) if (hrwork<40) { document.write("Hours worked:" + hrwork); document.write("Pay rate per Hour:" + payrate); document.write("Salary:" + (payrate * hrwork)); } else if (hrwork>40) { var regsal= parseFloat (40 * payrate); var overtimehrs= parseFloat (hrwork - 40); var overpayrate= parseFloat((payrate/2) + payrate); var overpay = parseFloat(overtimehrs * overpayrate); var gross = parseFloat (regsal + overpay); document.write("Hours worked:" + hrwork); document.write("Pay rate per Hour:" + payrate); document.write("Regular Salary:" + (payrate * hrwork)); document.write("Overtime Hours:" + overtimehrs); document.write("Overtime pay rate:" + overpayrate); document.write("Overtime pay:" + overpay); document.write("Total Gross Salary:" + gross); } } </script> </body> </html>

  • Answer:

    This is what you have, and what JavaScript sees: <script language="JavaScript" type="text/javascript"> function calculate() { // A bunch of code that implements calculate() } </script> So...you defined a function called calculate. But you never CALL it! Defining a function does just that, and only that. It defines the function. It does *NOT* run it. You need to call the function to make that happen: <script language="JavaScript" type="text/javascript"> function calculate() { // A bunch of code that implements calculate() } calculate(); // <-- Here you CALL the function. </script>

Ariel at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.