Have a look in the Help (index Script Editor => about). This should give you more insight into how the Script Editor is used.
For this example, you'd just need to select your button, make sure the 'click' event is in the 'Show' drop-down, select 'JavaScript' from the 'Language' drop-down and then paste the script into the script editing field.