My answer is very very similar to your last question. Just adapted slightly:
Sol = 'aaa' %is a char variable
userPrompt = 'Insert right word. You have 3 tries: ';
counter = 1;
while counter <= 3
userResponse = inputdlg(userPrompt);
if strcmpi(userResponse, Sol)
break;
end
fprintf('Incorrect. Try again.\n');
counter = counter + 1;
end
if counter <= 3
fprintf('Correct.\n');
end