Before anything, if you are lifting the Work value have to be negative, reason is because the formula to the work of the weight is:
*Photo to help you to visualize. (P = Weight Force, F = Force)
If you are lifting, you are exercising a force that opposes the Weight Force, Force up (lifting) and Weight Force down (gravity pulling).
This forms a 180 angle and the cos 180 = -1.
Well let's do the question:
Work (W) = -40 J (Joule = Kg x m^2/s^2)
(negative, explanation given)
Weight Force (P) = 10 N (Newton = kg x m/s^2)
Distance (D) = ?
W = P x d x cos theta
-> -40 = 10 x d x -1
-> -40 = -10 x d
-> d = -40/-10 (J/N)
-> d = 4 meters