Please take a look how it works!
Play around with the code and click on the "Run" button to view the result.