**Random numbers**:

- use Math.random() function to generate a random decimal number between 0 and 1 (0 can occur, but not 1)
- random whole numbers can be generated with a combination of multiplication and Math.floor() to round the number down to the nearest whole number e.g. return Math.floor(Math.rand\rom() * 10);
- to generate a whole number within a range, you can use something like: Math.floor(Math.random() * (max – min + 1)) + min

**Regular expressions**:

- Regular expressions find patterns within strings
- start and end a regular expression with ‘/’, with the pattern you want to find between, e.g. if you’re searching for the word ‘dog’, it’d be:
*/dog/* - add g to the regex to make it
*global –*ie will return all the matches in the string, not just the first one - add i to ignore case e.g.
*/dog/gi* - there are many special selectors in regex, to select a
*type*of value **\d**is the digit selector – it would find one digit in a string e.g.*/\d/g***+**after the selector (eg \d+) allows the matching of one or more**\s**is the whitespace selector – this will find ” ” (space), \r (carriage return), \n (newline), \t (tab), and \f (linefeed)**invert**a selector by using the uppercase letter e.g. \s selects whitespace, \S selects anything that is**not**whitespace

Advertisements