The following are my notes/observations about what Jen DeWalt did to complete her page:
- She does not actually use a button for the "click me" box. She uses a div and then styles it.
- The random color generator simply produces a hexadecimal color. Her function is as follows: "Math.random().toString(16).slice(2,8)"
- Math.random() => produces a random number between 0 and 1
- toString => converts the number into a string (as I am assuming the hexadecimal color can only be entered as a string). Also, by placing 16 in the parentheses, it returns a hexidecimal representation of the number.
- slice(x,y) => returns a part of the string starting at the character with index "x" and then stopping at and NOT including the "yth" character.
- The button itself has an href attribute assigned to "javascript:void(0);". That script is the smallest script that evaluates to 'undefined' which prevents Javascript from loading a new page. There are some good articles on that at Stack Overflow and Tizag.
- It looks like she is using JQuery for the rest of her function in 'random_background.js'. Here are my initial impressions which I will then try to validate later. The following comments are based on her function shown here:
$("#button").on("click", function () {
     $('body').css('background', randomColor());
});
- "#button" is the id of her anchor tag that says "Click me!"
- JQuery appears to do events similar to what I've learned but breaks it up a bit. It looks like you select the thing it should watch the event for, specify the event (i.e. click), and then tell it what to do...in this case, it's do the function.
- The function grabs the body and seeks to edit the css property "background" where it then puts in the randomColor() function which returns a hexadecimal value.
- As a reminder, "../" goes up one directory level.
Things to think about:
- I need to learn JQuery and compare it to how I currently understand events in Javascript.
- How else could I do the hexadecimal color generator? I kind of just broke down her equation and then used hers...how would I intuitively do it and do I like my version vs. hers?