ex30 and 31 with ifelse