In life we all face tests. As we grow and our faith grows, it is also tested.
Mufti Menk gives the example of someone who was worshipping for his whole life, but right at the end they gave up and were thrown into the hellfire. Similarly one was disobedient for his whole life but right at the end turned back to Allah and was rewarded Jannah.
No one knows when their time in this world is up. Never give up, even when we are hopeless Allahs mercy is there. Work hard to succeed in this world but also work hard to be successful in the life hereafter. By the will of Allah we will achieve great things.