|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Console Tricks!</title> |
| 6 | +</head> |
| 7 | +<body> |
| 8 | + |
| 9 | + <p onClick="makeGreen()">×BREAK×DOWN×</p> |
| 10 | + |
| 11 | + <script> |
| 12 | + const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }]; |
| 13 | + |
| 14 | + function makeGreen() { |
| 15 | + const p = document.querySelector('p'); |
| 16 | + p.style.color = '#BADA55'; |
| 17 | + p.style.fontSize = '50px'; |
| 18 | + } |
| 19 | + |
| 20 | + // Regular |
| 21 | + console.log('hello'); |
| 22 | + |
| 23 | + // Interpolated |
| 24 | + console.log('Hello I am a %s string', 'test'); |
| 25 | + // Styled |
| 26 | + console.log('%c Hello I am some great %s string', 'font-size:50px; background:red;', 'test'); |
| 27 | + |
| 28 | + // warning! |
| 29 | + console.warn('OH NOOO'); |
| 30 | + |
| 31 | + // Error :| |
| 32 | + console.error('CRAP!'); |
| 33 | + |
| 34 | + // Info |
| 35 | + console.info('Crocodiles eat 3-4 people per year'); |
| 36 | + |
| 37 | + // Testing |
| 38 | + // console.assert(1 === 2, 'Wrong'); |
| 39 | + const p = document.querySelector('p'); |
| 40 | + console.assert(p.classList.contains('ouch'), 'That is wrong!'); |
| 41 | + |
| 42 | + // clearing |
| 43 | + console.clear(); |
| 44 | + |
| 45 | + // Viewing DOM Elements |
| 46 | + console.log(p); // shows the actual element |
| 47 | + console.dir(p); |
| 48 | + |
| 49 | + // Grouping together |
| 50 | + console.clear(); |
| 51 | + dogs.forEach(dog => { |
| 52 | + console.log(`This is ${dog.name}`); |
| 53 | + console.log(`${dog.name} is ${dog.age * 7} dog years`); |
| 54 | + }); |
| 55 | + |
| 56 | + dogs.forEach(dog => { |
| 57 | + // console.group(`${dog.name}`); |
| 58 | + console.groupCollapsed(`${dog.name}`); |
| 59 | + console.log(`This is ${dog.name}`); |
| 60 | + console.log(`${dog.name} is ${dog.age * 7} dog years`); |
| 61 | + console.groupEnd(`${dog.name}`); |
| 62 | + }); |
| 63 | + |
| 64 | + |
| 65 | + // counting |
| 66 | + console.count('Wes'); |
| 67 | + console.count('Wes'); |
| 68 | + console.count('Wes'); |
| 69 | + console.count('Steve'); |
| 70 | + console.count('Wes'); |
| 71 | + console.count('Wes'); |
| 72 | + console.count('Wes'); |
| 73 | + console.count('Steve'); |
| 74 | + |
| 75 | + // timing |
| 76 | + console.time('fetching data'); |
| 77 | + fetch('https:/api.github.com/users/dianafisher') |
| 78 | + .then(data => data.json()) |
| 79 | + .then(data => { |
| 80 | + console.timeEnd('fetching data'); |
| 81 | + console.log(data); |
| 82 | + }); |
| 83 | + |
| 84 | + console.table(dogs); |
| 85 | + </script> |
| 86 | +</body> |
| 87 | +</html> |
0 commit comments