Passing exit code to calling script

In production I need to pass an exit code from a script that is being called 3 or 4 layers deep. I've created test scripts to play with it until I get it right. As you can tell, this is not my normal job. Perhaps I should have entered this in UNIX for Dummies section. Anyway, I keep losing the value of my variable. Can you please help? Thanks.

SCRIPT 1

#!/usr/bin/ksh
echo 'in test1'
EXITSTATUS=$?
if test2 [${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT 2

#!/usr/bin/ksh
echo 'in test2'
EXITSTATUS=$?
if test3 [${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT3

#!/usr/bin/ksh
echo 'in test3'
EXITSTATUS=99

try something like this:

#!/usr/bin/ksh
echo 'in test1'
EXITSTATUS=0
test2
EXITSTATUS=$?
if  [ ${EXITSTATUS} -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT 2

#!/usr/bin/ksh
echo 'in test2'
EXITSTATUS=0
test3
EXITSTATUS=$?
if  [ $EXITSTATUS -ne 0 ]
then
exit ${EXITSTATUS}
fi

SCRIPT3

#!/usr/bin/ksh
echo 'in test3'
EXITSTATUS=99
exit $EXITSTATUS

Thank you. I appreciate your help. It's working.