Need help making a counter controlled by a button
A way of many.
Aim: give you a lead without doing your work for you:

You need a clock source. This may be provided or you MAY have to provide / generate it.


Find how to cause JK flipflops to toggle. 
Arrange 5 toggling flip flops so 1st clocks 2nd, 2nd clocks 3rd etc. 


You now have a 5 stage counter. 


Find out what AND (or NAND) gates do. 
Arrange an AND gate to combine FF outputs as required to make an I_AM_AT_40 signal - use this to stop the clocking. 
Work out how to reset all flipflops and unstop the clocking. 
Ask if unclear.