If you apply the discount first:
39.99(1-.20)-10
=39.99(.8)-10
=31.99-10
=21.99
If you apply the gift card first:
(39.99-10.00)(1-.20)
=(29.99)(.8)
=23.99
You should apply the 20% discount first. The lowest final price is $21.99.