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
Related Q & A:
- A code for a comment box?Best solution by Yahoo! Answers
- Please help - how do I delete a profile?Best solution by Yahoo! Answers
- Could somebody please help me come up with a really cool msn name?Best solution by Yahoo! Answers
- Ps3 problem please help!?Best solution by Yahoo! Answers
- FINANCIAL AID PROBLEM, PLEASE HELP?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.