MATLAB: Guess the favorite color? MATLAB

how would i use matlab, to prompt the user to guess your favorite color? and then saying incorrect 3 tries and then says run out of chances. (new to matlab)

Best Answer

fav = 'red' ; % my favourite color
str = 0 ;
count = 0 ;
while str == 0
count = count+1 ;
prompt = 'What is my favourite color? ';
str2 = input(prompt,'s') ;
if strcmpi(fav,str2)
str = 1 ;
disp('you got the color correct')
elseif count == 3
str = 1 ;
disp('three trials over')
end
end
when prompted enter either red,blue,green,white,maroon, black,etc. any color.