if ( event.target == input2 )

The condition asks: "is the target of the event the input2 text field?"

That is, did the user press enter or return while the cursor was in the input2 text field?