Allah tells us the purpose for our creation as follows:
I only created jinn and man to worship Me. (Surat adh-Dhariyat: 56)
As stated in this verse, the purpose of man's existence on Earth is his being just a servant of Allah, worshipping Him and gaining His approval. Man is tested on this subject as long as he is on this Earth.