Here's a breakdown:
Y is a vowel when:
* It's the only vowel in a syllable:
* "my"
* "fly"
* "cry"
* It follows a consonant at the beginning of a word:
* "yes"
* "yellow"
* "yacht"
* It's at the end of a word and makes a vowel sound:
* "happy"
* "funny"
* "pretty"
Y is a consonant when:
* It's at the beginning of a word and makes a consonant sound:
* "yesterday"
* "young"
* "yummy"
* It's in the middle of a word and makes a consonant sound:
* "gym"
* "rhythm"
* "beyond"
In summary:
Y acts as a vowel when it makes a vowel sound, usually in the middle or at the end of a word. It acts as a consonant when it makes a consonant sound, usually at the beginning of a word.