What would be the proper code for the above mentioned scenario?