The easiest, most elementary way of writing a melody is as simple as writing out your chord progression and just using chord tones and quarter or 8th notes. Non-chord tones are what really make things interesting, but starting with what's actually in the chord underneath is the easiest way in my opinion. Just experiment, try each tone present in each chord over the given chord and all of the combinations between them all. Eventually, you'll learn how each interval reacts with each triad/chord and so much experimentation won't be necessary. But if you're looking for a good place to start, just layout your progression and just assemble a bunch of chord tones on top and see if you like it. If you don't, rinse and repeat. When you've gotten something you like, COPY IT and save the original. Then, try sprinkling in a few passing tones maybe, or a suspension. Like I said, it's with non-chord tones that things start to get fun, so might not even mind experimenting in this phase. Either way, this is basically (more or less) how I wrote my first piece in my Theory Lab in college. It's also very common in beginning sight-singing exercises, as non-chord tones tend to be a bit tough in context, for beginners. Also, read bandcoach's response. If you want to write the melody first, pick a key and work it backwards. See at what points which chords/triads/inversions sound the best to YOUR ears. (given that it's a musically sound choice). Start with chords that have the note in the melody in the chord and so on and so forth.