an alternate method that uses the recursion with COND and IF