A note on writing comedy. There are many authors who write a humorous tones, mostly satiric authors like Terry Pratchett (Discworld series) and Douglas Adams (Hitchhiker’s Guide to the Galaxy Series). However, humor is perhaps the most difficult genre to write because humor varies as everyone finds different things funny.
You might write a book that you believe is hilarious, but someone else might not be so amused. On the other hand, you may write a book that you are a very serious about and readers will see it as a joke.
Also, humor does not always come across the same in writing as it does when you tell a joke vocally. Wordplay, spelling, and written details, however, can only come across in writing. So, in order to know how to work humor into stories, learn about language, wordplay. Read other humor writers to get ideas.
And, above all, do not be discouraged if some people do not get your jokes. There will always be those who do not find you funny. Accept that and move on. However, if no one finds it funny…you may have a problem.