how to make a game object a child of antohter while game is playing

i am making a ninja game and when you aproach the sword a GUI will pop up saying press this button to eguip, and my problem is i don't no how to script it so when you pick it up it becomes a child of the character. If you could show me how to script that (preferably in javascript) that would be great!

sword.transform.parent = ninja.transform