Skip to main content

Posts

Showing posts from May, 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 b th 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 soo