Friday, May 30, 2014

Did You Know...

I recently added a "Did You Know" app to the sidebar of my blog. The app randomly picks a math/science/technology fact from a list, and displays it. I had to write the app myself (with JavaScript and HTML), because Blogger doesn't have an app like that built-in, and even if it did, I like to have control over my things.

To get technical: the data is stored on Firebase. The app reads the data from Firebase, and adds it all to an array. There is no way to tell how many items there are without reading all of them from Firebase. The app then looks at how many elements are in the array (call that number a) and then randomly chooses a number b from 1 to a. It then takes the bth element from the array, and displays it. (I know, I didn't have to store them all in an array, but it's easier that way.)

Because of the data storage method, I can add new facts very easily: I just have to go to Firebase and add the new fact to the database. Of course, my app updates as soon as I add the new data. I can also set up the app to read data from a different Firebase location, so I can easily have multiple apps with different themes. Here's a screenshot of a Minecraft-themed app, for example:


If anybody is interested in putting a version of the app on their blog, let me know! I'd be happy to set up a version of my app with another theme, such as astronomy, animals, or sports. I can also change the style to make the font pink or green, or give it a purple background, before I send you the code. The possibilities are endless.

To receive updates, subscribe now!

No comments:

Post a Comment