Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaScript code is not working properly  RSS feed

 
Ray Bell
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!