On Facebook I was chatting a stranger girl the girl asked for the phone number I gave her. But when I asked her number she replied she does not have one. After a while, a WhatsApp message came having a code. She insisted me to give that code. I refused. Was it a scam?
Yes, I'm sure they were trying to do something fishy, although I'm not sure I would call that a "scam", technically. They were probably actually trying to gain control of your account.
Codes are sent to your phone to verify that you actually have access to that phone. If you give those kinds of codes to somebody else, then they will be able to use them to prove they have access to your phone. As a result, the attacker might be able to access your email account even with two-step/two-factor authentication, or they might be able to access your whatsapp account, as might be the case in your situation.
I found the following article that might be relevant, it sounds like the same thing except that you received the request via Facebook.