To Remember – Math.floor


youHit to Math.floor(Math.random() * 2). This sets youHit to a random number that’s either 0 (which JavaScript reads as false) or 1 (which JavaScript reads as true).

Source Codecademy

Tips – CSS Selectors and HTML Branches


As i mentioned in a previous post, I’m learning HTML/Javascript at the moment via Codecademy and will post stuff I have learnt, so others who follow/Google can learn. These are just snippets, but the site is a great learning tool.

So CSS Selectors – CSS is a very powerful way of styling and positioning your HTML elements. The syntax is simple, you use the HTML element as the selector! Good example is if you want all your list elements to have a red background color:

 

Full code can be found here on JSFiddle.

 

li {
 background-color: red;
}

So the above example will highlight any list (li) element red, What if you want to more selective of what you want as red, say for example just any ordered (ol) list (li) elements red? Easy:

 

Full code can be found here on JSFiddle.

 

ol li {
 background-color: red;
}

So the above example will highlight any list (li) element that is child of a parent ordered list (ol) elements. This small example shows branching works within HTML documents and how CSS selectors traverses the tree using the simple parent/sibling relationships. This is very powerful. And as mentioned in a previous post, you can be more specific by giving a more specific branching.

 

Full code can be found here on JSFiddle.

 

 

ol li {
    background-color: red;
}
div ol li {
    background-color: purple;
}

Images courtesy of Codecademy.