Why won't this code pass all conditions , though it yield s the correct result?