Friday, December 27, 2019

Lab 32 Adding Up Times with Reduce

In this lab, I followed the instruction from JavaScript30 and recreated the Adding Up Times with Reduce 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_32.css"> inside the <head> tags to link the CSS file with my HTML file. Fourthly, I typed in <script src="Lab_32.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 32</h1><h2>Wei Jian Zhen</h2><h3>12/24/2019</h3></div>. Next, I inserted <ul> and <li> tags that made a list. 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 in:
  const timeNodes = Array.from(document.querySelectorAll('[data-time]'));
  const seconds = timeNodes
    .map(node => node.dataset.time)
    .map(timeCode => {
      const [mins, secs] = timeCode.split(':').map(parseFloat);
      return (mins * 60) + secs;
    })
    .reduce((total, vidSeconds) => total + vidSeconds);
    let secondsLeft = seconds;
    const hours = Math.floor(secondsLeft / 3600);
    secondsLeft = secondsLeft % 3600;
    const mins = Math.floor(secondsLeft / 60);
    secondsLeft = secondsLeft % 60;
    console.log(hours, mins, secondsLeft);
This makes the webpage functional. Knowing how to use JavaScript is useful to a web designer because it allows web designers to make website functional.

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


No comments:

Post a Comment