Suhani Goyal ,
When you say you needed a solution, I take it that you now have found the solution? because I didn't see any problem with the code, it runs just fine. If not, then you should've elaborated the problem a bit more.
If you meant to share this as a tips or tutorial for others to see, then you should use the feeds post.
If you want to showcase your code you should do it in one of those dedicated threads for code showrooms, like these ones: