Do not Regret for Failure, nor Exult for Achievement
A negative aspect of human nature is excessiveness. Exultation in fulfillment of desire and feeling excessive pain in disappointment is the weakness of human nature. People become overjoyed when something desirable happens. Sometimes it ends in pride and arrogance. On the other hand, people suffer from excessive grief in unexpected events. The Qur'an teaches us to remove both these marginal tendencies and adopt the path of balance. Allah says:
مَاۤ اَصَابَ مِنْ مُّصِیْبَةٍ فِی الْاَرْضِ وَ لَا فِیْۤ اَنْفُسِكُمْ اِلَّا فِیْ كِتٰبٍ مِّنْ قَبْلِ اَنْ نَّبْرَاَهَا اِنَّ ذٰلِكَ عَلَی اللهِ یَسِیْرٌ، لِّكَیْلَا تَاْسَوْا عَلٰی مَا فَاتَكُمْ وَ لَا تَفْرَحُوْا بِمَاۤ اٰتٰىكُمْ وَ اللهُ لَا یُحِبُّ كُلَّ مُخْتَالٍ فَخُوْرِ.
Every calamity that befalls the earth and your own selves, but it is recorded in a book (al-lawh al-mahfuz), long before I created it. It is easy for Allah. (You have been informed of this) so that you do not grieve over what you have lost or what you have got. And do not rejoice in what Allah gives you. Allah does not like the proud and arrogant. - Surah Hadid (57): 23-24
This verse says that everything good and bad that happens in the world happens according to Taqdir written in al-lawh al-mahfuz. So there is no need to be excessively saddened by any unpleasant incident. Unexpected events may cause some pain in the mind, which is human weakness. But one should not dwell on that pain or become a victim of excessive grief. Rather, he should be patient and keep in mind that everything happens by Allah's decision. A sense of joy in achieving something is human nature. There is nothing wrong with that. But there is no room to exult beyond the level of normal happiness. One should not consider what has been achieved as merely the result of his own efforts. Rather, he should thank Allah for what he has acquired. This is the balanced path.
A hadith also sheds light on this matter. Abdullah ibn Abbas r.a. said, One day I was sitting behind the Prophet sallallahu alaihi wa sallam. He told me-
يَا غُلَامُ إِنّي أُعَلِّمُكَ كَلِمَاتٍ، احْفَظِ اللهَ يَحْفَظْكَ، احْفَظِ اللهَ تَجِدْهُ تُجَاهَكَ، إِذَا سَأَلْتَ فَاسْأَلِ اللهَ، وَإِذَا اسْتَعَنْتَ فَاسْتَعِنْ بِاللهِ، وَاعْلَمْ أَنَّ الأُمَّةَ لَوْ اجْتَمَعَتْ عَلَى أَنْ يَنْفَعُوكَ بِشَيْءٍ لَمْ يَنْفَعُوكَ إِلَّا بِشَيْءٍ قَدْ كَتَبَهُ اللهُ لَكَ، وَلَوْ اجْتَمَعُوا عَلَى أَنْ يَضُرُّوكَ بِشَيْءٍ لَمْ يَضُرُّوكَ إِلَّا بِشَيْءٍ قَدْ كَتَبَهُ اللهُ عَلَيْكَ، رُفِعَتِ الأَقْلَامُ وَجَفَّتْ الصُّحُفُ.
Oh dear boy! I'm teaching you some words. If you protect Allah (i.e. obey His commandments), then Allah will protect you. If you protect Allah, then you will find Him in front of you. When you ask for something, ask for it from Allah. If you ask for help, ask for it from Allah. Know that if the whole world unite to do any good to you, they would not be able to do that to you except what Allah has written for you. And if they unite to harm you, you will not be able to do any harm except what Allah has written for you. - Tirmidhi, Hadith 2516
We also learn from this hadith that whatever happens in human life, good or bad, is predestined. So if you lose something or don't get something you want, there is nothing wrong with you if you feel worried. Because, this failure happened by Allah's decision. Similarly, you should not be exultant when something is achieved. This is not the result of your efforts. Rather, it is the gift from God.
One thing needs to be clear here, no one knows what Allah has written in his destiny. He does not need to think about what is written in taqdir. His responsibility is to do his job with devotion. If someone tries with sincerity and devotion, Allah opens for him the way to do good deeds. The Holy Quran says:
اِنَّ سَعْیَكُمْ لَشَتّٰی، فَاَمَّا مَنْ اَعْطٰی وَ اتَّقٰی، وَ صَدَّقَ بِالْحُسْنٰی، فَسَنُیَسِّرُهٗ لِلْیُسْرٰی، وَ اَمَّا مَنْۢ بَخِلَ وَ اسْتَغْنٰی، وَ كَذَّبَ بِالْحُسْنٰی، فَسَنُیَسِّرُهٗ لِلْعُسْرٰی.
Your efforts are varied. (Hence its results are also different). So whoever spends wealth in the way of Allah and practices taqwa and accepts what is good (Islam) as true, I will certainly make easy for him the easiest of things (good deeds, which is the path to Jannah). On the other hand, whoever is miserly, reckless and rejects the good (Islam), I will certainly make the hardest thing (Hell) easy for him. - Surah Al Lail (92): 4-10
It is understood that if one does good deeds with devotion, Allah will make the path of virtue and the path of Paradise easier for him. On the other hand, if someone stubbornly takes the opposite path, his path is not blocked too. He is allowed to go to his own place.
So the duties of a believer are as follows-
a. They should fulfill their duty with devotion. Then Allah will make the path of good deeds easy for them.
b. They should not be overly saddened by loss or failure. Rather, everything happens according to the decision of Allah. So, they should remain patient.
c. They should not be exultant on any achievement and consider it as the result of their own efforts. Rather, it is the result of the grace of Allah; he should keep this faith in his heart.