@swoop
Since it appears that you are really taking the time to learn, I will put my little sample script below (with its output). Ordinarily, I would wait to see some actual effort or for an explicit request. Keep in mind that this is just one way, my way. As with any language, there's usually many ways to say the same thing. The sample script has terse documentation, but hopefully enough to help understand what each block of code is doing.
I am hiding it behind the "Show Hidden Contents" banner in case you would rather not be tempted to see it while browsing the topic.