MATLAB: Matrix dimensions must agree – 3 chances loop

Hi, I need help with a code I'm trying to run.
I'm trying to run it so you have 3 chances to guess a string variable correctly, and after the third, it says incorrect, or if any of the guesses are correct then the code ends and just says you have guessed correctly.
The code is shown below that I am using: (The error shown is that Matrix dimensions must agree – the code runs perfectly with correct guesses or when I guess food which has 5 letters)
FavFood=('Pizza');
y=input('What is my favourite Food? ','s');
if y==FavFood
disp('Well done, you guessed correctly');
else x=input('Sorry, you guessed wrong. Try again: ','s');
if x==FavFood
disp('Well done, you guessed correctly');
else z=input('Sorry, you guessed wrong. Try again: ','s');
if z==FavFood
disp('Well done, you guessed correctly');
else disp('Sorry, you ran out of chances.');
end
end
end
Many thanks,
EDIT: typo

Best Answer

Your fundamental problem is how you are doing string compares. Do not use the == operator since that is an element-wise operator and is not doing what you think it is doing in your if-tests. Instead, use a function that works with strings, such as strcmpi. E.g.,
if strcmpi(y,FavFood)