<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ephrathah Oyedoh</title>
    <description>The latest articles on DEV Community by Ephrathah Oyedoh (@ephieo).</description>
    <link>https://dev.to/ephieo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F468293%2Febb8b042-01d2-4e3b-b8ef-a0a6c1547eb2.jpeg</url>
      <title>DEV Community: Ephrathah Oyedoh</title>
      <link>https://dev.to/ephieo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ephieo"/>
    <language>en</language>
    <item>
      <title>Why bother with TDD?</title>
      <dc:creator>Ephrathah Oyedoh</dc:creator>
      <pubDate>Wed, 27 Oct 2021 08:34:36 +0000</pubDate>
      <link>https://dev.to/ephieo/why-bother-with-tdd-5mn</link>
      <guid>https://dev.to/ephieo/why-bother-with-tdd-5mn</guid>
      <description>&lt;h3&gt;
  
  
  Disclaimer :
&lt;/h3&gt;

&lt;p&gt;I am still very much learning about best&lt;br&gt;
practices and clean code so all views shared are personal to me and where I currently am in my coding journey. &lt;/p&gt;

&lt;p&gt;Testing. Ever since I started embarking on my coding journey, testing has been nothing to me other than a nemesis that I avoided at all costs. Delegating the task of testing was always easy up until now because you don't have to look too far in a project for green tick addicts that equate testing to pure joy and happiness. &lt;/p&gt;

&lt;h3&gt;
  
  
  What is TDD?
&lt;/h3&gt;

&lt;p&gt;TDD stands for 'Test Drive Development'. &lt;a href="https://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt; is a software development process that involves writing failing tests before you actually write any fully developed software and continuously testing the software against all tests cases. TDD is a popular alternative to writing software and then testing later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why implement TDD in your work ?
&lt;/h3&gt;

&lt;p&gt;I would say that TDD is the code equivalent to cleaning as you go in the kitchen compared to cleaning the kitchen after a very messy Christmas dinner. TDD is more effective in forming the habit of caring about your code and the effects it leaves behind. It doesn't really matter if your code works when you don't know if it will break or even worse you have no clue when your code will break. &lt;/p&gt;

&lt;p&gt;I'm an apprentice at 8th Light and currently entering my second month at the company. I was tasked with building a tic tac toe (noughts  &amp;amp; crosses) CLI game in ruby. The aim of the project wasn't to get the game working but to challenge me to learn another language while learning how to implement TDD. &lt;/p&gt;

&lt;p&gt;I started building my app while using both Ruby and Rspec for the first time. I had experiences with classes but it definitely wasn't a strong point for me. This challenged me to learn a more object oriented approach to programming while thinking about how to implement unit and integration tests. &lt;/p&gt;

&lt;h3&gt;
  
  
  What are unit and integration tests ?
&lt;/h3&gt;

&lt;p&gt;Unit testing is the process of testing a unit. In programming that unit is most often a function or the smallest amount of code you can isolate in a codebase. Integration testing pretty much does what is says on the label. Integration tests help test the flow of an application forming tests for where units of software are connected together. Therefore you are testing how your software integrates and how it combines different functionalities. &lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of TDD ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You only write code that's needed.&lt;/li&gt;
&lt;li&gt;Modular design.&lt;/li&gt;
&lt;li&gt;High Test Coverage.&lt;/li&gt;
&lt;li&gt;Easier to maintain code.&lt;/li&gt;
&lt;li&gt;Easier to refactor.&lt;/li&gt;
&lt;li&gt;Easier Debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of TDD ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Slow process.

&lt;ul&gt;
&lt;li&gt;Writing test before your software takes time, even straight forward implementations will take a little longer.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;It takes a team.

&lt;ul&gt;
&lt;li&gt;TDD becomes pointless if only one person on a team implements it. TDD influences the planning of code so a team approach is necessary to plan and implement code in that manner. There is no point cleaning the kitchen when five other people are making a mess and never cleaning.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Tests need t be maintained when code is changed.

&lt;ul&gt;
&lt;li&gt;Similar to the slow process of writing tests it also then takes more time to maintain said tests.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So is TDD for you ? If it's not that's understandable because it definitely wasn't for me and right now with a failing test in front of me I'm reconsidering this conclusion. I joke. &lt;/p&gt;

&lt;p&gt;Overall my experience with TDD has been good the only downside being the effort it requires, I personally think it pays off in the end. Currently my greatest benefit from TDD has been Thinking through why I actually want or need to write a specific piece of code. TDD has helped me cut down on repeated and redundant code.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Resources :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/advantages-and-disadvantages-of-test-driven-development-tdd/"&gt;Advantages and disadvantages of Test Driven Development (TDD)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://smartbear.com/learn/automated-testing/what-is-unit-testing/"&gt;What is unit testing?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tdd</category>
      <category>testing</category>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Beginners attempt at creating a Javascript stopwatch. </title>
      <dc:creator>Ephrathah Oyedoh</dc:creator>
      <pubDate>Tue, 15 Sep 2020 18:08:23 +0000</pubDate>
      <link>https://dev.to/ephieo/beginners-attempt-at-creating-a-javascript-stopwatch-4kg6</link>
      <guid>https://dev.to/ephieo/beginners-attempt-at-creating-a-javascript-stopwatch-4kg6</guid>
      <description>&lt;h1&gt;
  
  
  Disclaimer:
&lt;/h1&gt;

&lt;p&gt;I am still very new to tech so If I get anything wrong please kindly correct me and share resources that may help me improve. &lt;/p&gt;

&lt;p&gt;I decided to work on a side project that helped me revise one of the workshops from the past week of my Bootcamp, that focused on DOM rendering using components and modularisation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tech Stack
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Javascript &lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;HTML &lt;/li&gt;
&lt;li&gt;Github&lt;/li&gt;
&lt;li&gt;Netlify &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Design and concept creation
&lt;/h1&gt;

&lt;p&gt;I started off designing what I wanted my Stopwatch to look like on &lt;a href="https://www.figma.com"&gt;Figma&lt;/a&gt;, I created the following wireframe/design.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w6pqf5Hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cte8bgxai7uzsnmhodi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w6pqf5Hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cte8bgxai7uzsnmhodi5.png" alt="Screen Shot 2020-09-13 at 12.05.02" width="880" height="319"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Boilerplate
&lt;/h1&gt;

&lt;p&gt;After creating what I aimed to achieve I started by creating my basic boilerplate: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;li&gt;date.js (that I renamed to stopwatch.js)&lt;/li&gt;
&lt;li&gt;stopwatch.css&lt;/li&gt;
&lt;li&gt;createElement.js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I created a &lt;code&gt;main-container&lt;/code&gt; , &lt;code&gt;header&lt;/code&gt; and &lt;code&gt;timer-container&lt;/code&gt; sections.&lt;br&gt;
I refer to the stopwatch as timer occasionally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nx"&gt;DOCTYPE&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UTF-8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;viewport&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;width=device-width, initial-scale=1.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;
      &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://fonts.googleapis.com/css2?family=Share+Tech+Mono&amp;amp;display=swap&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stylesheet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Stop&lt;/span&gt; &lt;span class="nx"&gt;Timer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stylesheet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stopwatch.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;defer&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stopwatch.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;section&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/header&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;timer-container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/section&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h1&gt;
  
  
  Abstracting .createElement()
&lt;/h1&gt;

&lt;p&gt;I then created the create element function and called it &lt;code&gt;h&lt;/code&gt; for HTML. &lt;/p&gt;

&lt;p&gt;You can see how this is done in the following workshop :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/oliverjam/learn-dom-rendering"&gt;https://github.com/oliverjam/learn-dom-rendering&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After creating the h() function I then proceeded to render the elements in &lt;code&gt;stopwatch.js&lt;/code&gt;  onto the DOM by using the h() function and appending it to the timer-container div.&lt;/p&gt;

&lt;p&gt;I used export default to export the h() function to stopwatch.js. Remember to give the script tag a type that equals to module (&lt;code&gt;type=module&lt;/code&gt;) so that Javascript knows that you are creating and using modules to connect your code.&lt;/p&gt;

&lt;p&gt;I understand that it may look like I'm taking the longer route to create things but please take into account that I am trying to implement the work taught in the workshop linked above. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating elements and rendering UI
&lt;/h1&gt;

&lt;p&gt;I then created a &lt;code&gt;stopwatch()&lt;/code&gt; function in &lt;code&gt;stopwatch.js&lt;/code&gt; I imported the h() function from &lt;code&gt;createElement.js&lt;/code&gt;  on line 3. I then created variables holding the individual elements and then made those elements children of a &lt;code&gt;timerContainer&lt;/code&gt; (line 23) variable and rendered it by appending it to the timer-container that I required using &lt;code&gt;querySelector&lt;/code&gt; on line 6.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pcb1SDjY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zchmi30mxmr8nqoniph6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pcb1SDjY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zchmi30mxmr8nqoniph6.png" alt="Screen Shot 2020-09-12 at 15.35.35" width="880" height="711"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After rendering these elements my stopwatch looked like this:&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zt0u5LPU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/smwnninoqa40wt0w3dso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zt0u5LPU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/smwnninoqa40wt0w3dso.png" alt="Screen Shot 2020-09-12 at 15.15.30" width="880" height="1012"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessibility and spacing
&lt;/h3&gt;

&lt;p&gt;I use borders to understand my spacing so that I can visually determine where and how far a container spans.&lt;br&gt;
I also changed the colour of green slightly from #6d884d ⇒ #6d9b4d to make the site more accessible because lighthouse flagged the contrast. You can access lighthouse in chrome dev tools and it gives you a report on how "accessible" your site is. You can also alter the contrast in dev tools in the styles section until the colours have enough contrast.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Inspect ⇒ Elements ⇒ Styles ⇒ * click the element you want to inspect and change the colour until it says contrast ratio is correct *&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JFqZc33R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ml8sjuoovwcmk1tbbwxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JFqZc33R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ml8sjuoovwcmk1tbbwxl.png" alt="devtools" width="880" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://remysharp.com/2017/08/17/contrast-ratio-in-devtools"&gt;Image Source&lt;/a&gt;&lt;br&gt;
&lt;br&gt; &lt;br&gt;
I then completely forgot about buttons so went back to create and render both the buttons and a heading for the page.&lt;br&gt;
&lt;br&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mhETTK9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0petrgn1m33wmvf9yvzp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mhETTK9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0petrgn1m33wmvf9yvzp.png" alt="heading ui" width="880" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uv16JX4a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sbodhgtf0bvxl0zuv87j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uv16JX4a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sbodhgtf0bvxl0zuv87j.png" alt="buttons ui" width="880" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating buttons and a heading my stopwatch looked like this: &lt;br&gt;
&lt;br&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B7Pb8Eje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eni177fewuocdiyhkn7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B7Pb8Eje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eni177fewuocdiyhkn7f.png" alt="app progress 3 " width="880" height="1100"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
So now my app was pretty but not functional. &lt;br&gt;
My next step was to create a function that would alternate time I used &lt;a href="https://www.youtube.com/watch?v=z2Tmvhm5wd4&amp;amp;list=TLPQMTIwOTIwMjDCn4VfmUhaIg&amp;amp;index=7&amp;amp;ab_channel=CodingGator"&gt;this&lt;/a&gt; Youtube tutorial for guidance. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Time variables
&lt;/h1&gt;

&lt;p&gt;Before creating the functions we need we need to create variables for seconds, minutes and hours (sec, min, hr) and set them to zero (these are the variables that will increment every second, minute or hour).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1yAnJhXs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4chiv8dratxpoctfr6k4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1yAnJhXs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4chiv8dratxpoctfr6k4.png" alt="time variables " width="604" height="122"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  startTime() Function
&lt;/h1&gt;

&lt;p&gt;I started by creating a function that would allow me to increment seconds, minutes and hours. The conditions of the if statements for seconds and minutes was that if it was less than 59 then increment the specified counter but if more then that count would be set 0 while the higher time count was incremented. &lt;/p&gt;

&lt;p&gt;So if it was 59 seconds (00:00:59) then it would then be 1 min after and the seconds counter would return to 0 while the min would increment + 1 (00:01:00).  The hour's condition was that if it was less than 24 then increment but the hours surpass 24 hours then it should reset to 0. &lt;/p&gt;

&lt;p&gt;In the code blocks for the if statements the "00"'s were selected and their text content altered through a print function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V_vU_Y52--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wef5cb4grmak4qn8xg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V_vU_Y52--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wef5cb4grmak4qn8xg8.png" alt="if statements" width="880" height="594"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Print() Function
&lt;/h1&gt;

&lt;p&gt;The print function takes a value (val) as an argument. it has an if statement with the condition that if the value is less than or equal to 9 that the function should return "0" + the specified value. So if the value is. 3 secs then print() will return "03". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sDrU0whp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yfn4jq28oeukutpltssx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sDrU0whp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yfn4jq28oeukutpltssx.png" alt="print()" width="880" height="253"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Start(), Reset() and Pause() Functions
&lt;/h1&gt;

&lt;p&gt;For the start and pause functions the start button was selected using &lt;code&gt;getElementById()&lt;/code&gt; and the button was either disabled for start (to prevent repeated clicks) or active when the stopwatch was paused so you could restart.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Start()
&lt;/h3&gt;

&lt;p&gt;In the start function, the interval was set for 1000ms because 1000ms = 1s. I was curious to how &lt;code&gt;setInterval()&lt;/code&gt; actually works, well I was mainly curious about what the set time did. The answer? it's in the name ;)&lt;br&gt;
setInterval takes a callback function as an argument and runs that function after a set interval. So if you enter 1000ms it will run that function every second. &lt;br&gt;
In our case we want the set time variables to increase and have those values printed to our "00" elements. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pause() function
&lt;/h3&gt;

&lt;p&gt;In the pause() function we clear the interval using &lt;code&gt;clearInterval()&lt;/code&gt; with the setInterval variable &lt;code&gt;t&lt;/code&gt; as an argument. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reset() function
&lt;/h3&gt;

&lt;p&gt;In the reset function, we also clear the interval and reset the time variables (sec, min, hr) to 0 and replace the text content of the "00" h2 elements. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uvj7MqEX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0rs5gl54qrrzojam728r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uvj7MqEX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0rs5gl54qrrzojam728r.png" alt="start,reset,pause" width="880" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After completing these functions all I needed to do was select the buttons from the DOM (I used &lt;code&gt;querySelector()&lt;/code&gt;) and create "click" event listeners with the start(), pause() and reset() functions as arguments. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KUBPNQjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3bfbqa333ql66u38h4av.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KUBPNQjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3bfbqa333ql66u38h4av.png" alt="query selector and variables" width="880" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zLu8tJzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8ssk3hqga1dwj1dfkep1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zLu8tJzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8ssk3hqga1dwj1dfkep1.png" alt="eventlistener" width="880" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After fixing some programmer errors I had a working stopwatch that was pretty as well as functional. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  MyResult
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://ephie-stopwatch.netlify.app/"&gt;Click here to view my stopwatch.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hMoqlQhd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/loowpelhsuq1rl7hr8np.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hMoqlQhd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/loowpelhsuq1rl7hr8np.png" alt="Screen Shot 2020-09-13 at 12.12.52" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've missed anything out please let me know.&lt;br&gt;
You can view my source code &lt;a href="https://github.com/ephieo/Stopwatch"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/EphieOyedoh"&gt; My Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>sideprojects</category>
    </item>
  </channel>
</rss>
