Sometimes we can use 'what' and 'which' interchangeably but there are a lot of cases when it's better to use the certain word.
When do we use 'What'?
'What' can be used before nouns. We use this question word when it is clear that there is a wide choice of possible answers.
For example π
What cars do you like?
What animals do you have?
When do we use 'Which'?
'Which' can also be used before nouns. We use it when it is clear that there are not so many possible answers.
'Which' is also used with 'one' or 'of'.
For example π
Which color do you like? Red or black?
Which hand did you hurt?
Which of these houses do you choose?
May I take a cookie? Which one may I take?