Functions - Example 2
This program demonstrates a magic trick involving numbers, and uses functions to do so. I have defined a function called hundreds() which gives you the hundreds digit of a three-digit number, a function called tens() which gives you the tens digit of a number, and a function called units() which gives you the units digit. It also uses a function called assemble() which takes three digits and assembles them into a three-digit number.
Here's the trick, then. I want you to think of a three-digit number where the first digit and third digit are different (i.e. not a number like 474). I will do a little calculation on your number, and I bet I get the answer 1089.
Try reloading this page and type in a different three-digit number.