Error with file test script

Dear friends

i am getting error when i run below script

#!/bin/bash
echo "Enter the name of the file"
read file_name
if [ -f $file_name ]
then
If [ -w $file_name ]
then
echo "add some text to quit ctrld"
cat >> $file_name
else
echo "the file does not have write permission"
fi
else
echo "$file_name does not exist"
fi
~

the error message is :

$ ./hello
Enter the name of the file
dddd
': not a valid identifier
./hello: line 16: syntax error: unexpected end of file

ibrahims@N-5CG613336K ~
$

any help please ? any advises as well how to debug such code or how to debug in general using vi editor is highly appreciated

Moderator comments were removed during original forum migration.