Friday, December 27, 2019

Lab 23 Dev Tools Domination

In this lab, I followed the instruction from JavaScript30 and recreated the Dev Tools Domination activity. First off, I made the HTML, CSS, and JavaScript files. Secondly, the <html>, <head>, <body>, <meta>, and <title> tags were already inserted in the HTML file. Thirdly, I typed in <link rel="stylesheet" type="text/css" href="Lab_23.css"> inside the <head> tags to link the CSS file with my HTML file. Fourthly, I typed in <script src="Lab_23.js" type="text/javascript"></script> inside the <body> tags which linked my JavaScript file with my HTML file. Inside the <body> tags, I typed the heading for the lab which has my name, date, and lab number with <div id="heading"><h1>Lab 23</h1><h2>Wei Jian Zhen</h2><h3>12/24/2019</h3></div>. After that, I typed <p onClick="makeGreen()" id="main">Click!</p> for the clickable text that turns the text green and big. Lastly, I made the copyright notice with <p> and <div> tags. For the CSS I did html {width: 100%; height: auto;} body {background-color: #00FFA8; min-width: 100%; min-height: 100%;} to give the webpage a background color and make the webpage responsive to screen size changes. #heading {text-align: center; font-size: 16px;} to center the heading of the lab. #copyright {font-size: 16px; font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", "serif"; font-weight: normal; padding-left: 1%; padding-right: 1%;} to change the font of the copyright notice. For the JavaScript, I typed:

// JavaScript Document

const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }];
    function makeGreen() {
      const p = document.querySelector('p');
      p.style.color = '#00ff00';
      p.style.fontSize = '50px';
    }
    // Regular
    console.log('hello');
    // Interpolated
    console.log('Hello I am an awful string!', '💩');
    // Styled
    // console.log('%c I am some great text', 'font-size:50px; background:red; text-shadow: 10px 10px 0 blue')
    // warning!
    console.warn('Warning');
    // Error :|
    console.error('ERROR!');
    // Info
    console.info('Crocodiles eat 3-4 people per year');
    // Testing
    const p = document.querySelector('p');
    console.assert(p.classList.contains('ouch'), 'That is wrong!');
    // clearing
    console.clear();
    // Viewing DOM Elements
    console.log(p);
    console.dir(p);
    console.clear();
    // Grouping together
    dogs.forEach(dog => {
      console.groupCollapsed(`${dog.name}`);
      console.log(`This is ${dog.name}`);
      console.log(`${dog.name} is ${dog.age} years old`);
      console.log(`${dog.name} is ${dog.age * 7} dog years old`);
      console.groupEnd(`${dog.name}`);
    });
    // counting
    console.count('Max');
    console.count('Max');
    console.count('Ethan');
    console.count('Ethan');
    console.count('Max');
    console.count('Ethan');
    console.count('Max');
    console.count('Ethan');
    console.count('Ethan');
    console.count('Ethan');
    console.count('Ethan');
    console.count('Ethan');
    // timing
    console.time('fetching data');
    fetch('https://api.github.com/users/wesbos')
      .then(data => data.json())
      .then(data => {
        console.timeEnd('fetching data');
        console.log(data);
      });
    console.table(dogs);

This shows how you can utilize console.log commands in JavaScript. Knowing how to use dev tools is useful to a web designer when troubleshooting the code.

Link: http://techteach.us/Web2020/ZWeiJian/WCP/Labs/Lab_23/Lab_23.html


No comments:

Post a Comment