Nasdaq logs gains for the third straight week