• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

JavaScript code is not working properly

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just started learning JavaScript this week and I have to give in an assignment with a form that gets input, makes a calculation, and gives output. I think I figured it out, but the output is not correct. Can someone please help me figure out why this code is not working? This is the .js code.


The regular hours work, but I don't get the extra 4 dollars for the overtime hours. For example, if I put in 60, I get 480, instead of 560.
 
author & internet detective
Posts: 41582
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you getting 560? (of 480) Overtime hours is 20 in your example.

20*8 + 60*4
160+240
400
 
Ray Bell
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. It's the opposite of what you describe. The regular hours are paid 8 and hour, and overtime gets 12 and hour. Instead I did this: 60 hours * 8(regular pay) plus 20(overtime hours) get and additional 4/hour.
so it's 60 * 8
plus   20 * 4.

I eventually got it to work by moving the if statement after the nested loop, like so:

I'm sure this was not the best way to do this. If anyone has any suggestions on a simpler way to do this, please share.
Thanks
 
What a show! What atmosphere! What fun! What a tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic