|
11 | 11 | <script> |
12 | 12 | const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }]; |
13 | 13 |
|
| 14 | + /* |
| 15 | + * Dev Tool Tip |
| 16 | + * If you see something happening but can't find the code here is a trick with Attribute Modifications |
| 17 | + * With devtools inspect the element > break on... > attribute modifications |
| 18 | + * This adds a breakpoint and will pause where the line of code is causing the attribute |
| 19 | + */ |
14 | 20 | function makeGreen() { |
15 | 21 | const p = document.querySelector('p'); |
16 | 22 | p.style.color = '#BADA55'; |
|
20 | 26 | // Regular |
21 | 27 | console.log('hello'); |
22 | 28 |
|
23 | | - // Interpolated |
| 29 | + // Interpolated (%s = simple function to replace something in a string) |
24 | 30 | console.log('Hello I am a %s string!', '💩'); |
25 | 31 |
|
26 | | - // Styled |
| 32 | + // Backticks do the same thing as the interpolation example above |
| 33 | + const poo = '💩'; |
| 34 | + console.log(`Hello I am a ${poo} string!`); |
| 35 | + |
| 36 | + // Styled (%c = lets you style things in the console) |
27 | 37 | // console.log('%c I am some great text', 'font-size:50px; background:red; text-shadow: 10px 10px 0 blue') |
28 | 38 |
|
29 | 39 | // warning! |
30 | 40 | console.warn('OH NOOO'); |
31 | 41 |
|
32 | 42 | // Error :| |
33 | | - console.error('Shit!'); |
| 43 | + console.error('Shitballs!'); |
34 | 44 |
|
35 | 45 | // Info |
36 | 46 | console.info('Crocodiles eat 3-4 people per year'); |
|
44 | 54 | console.clear(); |
45 | 55 |
|
46 | 56 | // Viewing DOM Elements |
47 | | - console.log(p); |
48 | | - console.dir(p); |
| 57 | + console.log(p); // shows a matching paragraph in the DOM |
| 58 | + console.dir(p); // dir shows all properties and methods of an object |
49 | 59 |
|
50 | | - console.clear(); |
| 60 | + console.clear(); // clears out the console |
51 | 61 |
|
52 | 62 | // Grouping together |
53 | 63 | dogs.forEach(dog => { |
54 | | - console.groupCollapsed(`${dog.name}`); |
| 64 | + // console.group(`${dog.name}`); // expands all of the log |
| 65 | + // console.groupCollapsed(`${dog.name}`); // puts logged items in a dropdown |
55 | 66 | console.log(`This is ${dog.name}`); |
56 | 67 | console.log(`${dog.name} is ${dog.age} years old`); |
57 | 68 | console.log(`${dog.name} is ${dog.age * 7} dog years old`); |
58 | 69 | console.groupEnd(`${dog.name}`); |
59 | 70 | }); |
60 | 71 |
|
61 | 72 | // counting |
62 | | - |
63 | | - console.count('Wes'); |
64 | | - console.count('Wes'); |
65 | | - console.count('Steve'); |
66 | | - console.count('Steve'); |
67 | | - console.count('Wes'); |
68 | | - console.count('Steve'); |
69 | | - console.count('Wes'); |
70 | | - console.count('Steve'); |
71 | | - console.count('Steve'); |
72 | | - console.count('Steve'); |
73 | | - console.count('Steve'); |
74 | | - console.count('Steve'); |
| 73 | + console.count('Ponybuckets'); |
| 74 | + console.count('Bernard'); |
| 75 | + console.count('Madoff'); |
| 76 | + console.count('Madoff'); |
| 77 | + console.count('Bernard'); |
| 78 | + console.count('Madoff'); |
| 79 | + console.count('Bernard'); |
| 80 | + console.count('Madoff'); |
| 81 | + console.count('Madoff'); |
| 82 | + console.count('Madoff'); |
| 83 | + console.count('Madoff'); |
| 84 | + console.count('Madoff'); |
75 | 85 |
|
76 | 86 | // timing |
77 | 87 | console.time('fetching data'); |
|
82 | 92 | console.log(data); |
83 | 93 | }); |
84 | 94 |
|
| 95 | + // table - for displaying an array in a table |
85 | 96 | console.table(dogs); |
86 | 97 |
|
87 | 98 | </script> |
|
0 commit comments