<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Claudia on Medium]]></title>
        <description><![CDATA[Stories by Claudia on Medium]]></description>
        <link>https://medium.com/@iamclaudiajayne?source=rss-8a0954e9b178------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9OnRUUiYTp8MNluhuTMxvg.png</url>
            <title>Stories by Claudia on Medium</title>
            <link>https://medium.com/@iamclaudiajayne?source=rss-8a0954e9b178------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 14:29:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamclaudiajayne/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Analogue Clock using HTML,CSS and JavaScript]]></title>
            <link>https://iamclaudiajayne.medium.com/analogue-clock-using-html-css-and-javascript-3a205b18039f?source=rss-8a0954e9b178------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a205b18039f</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Claudia]]></dc:creator>
            <pubDate>Sun, 21 Nov 2021 00:20:22 GMT</pubDate>
            <atom:updated>2024-07-08T01:45:37.657Z</atom:updated>
            <content:encoded><![CDATA[<p>A while ago, I was asked to make an Analogue clock using HTML, CSS and JavaScript.</p><p>This was actually quite fun! The interviewer did have different opinions to me about some of my ideas with the setInterval and redrawing of the clock.</p><p>What I will share here is my solution that I have tweaked heavily after the interview. Basically, this is what they would have received from me if it was an at-home test.</p><p>First, I dealt with the clock and the hands and decided to leave the numbers ’til the end.</p><p>Most of my functions looked like duplicates with minor changes working out the hand, the minute and the seconds so I also fixed that up into the one helper function.</p><p>Instead of breaking it all down into what is happening, here is the codepen.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fstamfette%2Fembed%2Fpreview%2FyLorNaJ%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DyLorNaJ&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fstamfette%2Fpen%2FyLorNaJ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/78d0824c884cb949e8cac085fd5f6b74/href">https://medium.com/media/78d0824c884cb949e8cac085fd5f6b74/href</a></iframe><p>Essentially, the CSS draws a 400px by 400px div on the page and uses border-radius to make a circle.</p><p>The hands are positioned “absolute” and we run the code every second to redraw the position of the hands. <em>The interview’s opinion was to make the setInterval every millisecond and compare if the current minute is the same as the previous and then transform whereas I am redrawing it every millisecond.</em></p><p><em>You could totally implement that and change my code around if you so wish or take on that advice for your clock!</em></p><p>There are 60 seconds in a minute and 60 minutes in an hour so calculating that on a circle (360deg angle) is simple math. You need to also remember that with hours, it is slightly different as there are only 12 hours.</p><p>The other thing to remember is that on an actual clock, if the time is say, 10:50 pm, the hour hand isn’t at 10; it is closer to 11.</p><p>Finally, when it came to adding the minutes to the clock, I couldn’t be bothered hardcoded the markup so I used Javascript to add them to the DOM.</p><h3>The final Code</h3><h4>Markup</h4><pre>&lt;div class=&quot;container&quot;&gt;<br>  &lt;div class=&quot;circle&quot;&gt;<br>      &lt;div class=&quot;hand second&quot;&gt;&lt;/div&gt;<br>      &lt;div class=&quot;hand minute&quot;&gt;&lt;/div&gt;<br>      &lt;div class=&quot;hand hour&quot;&gt;&lt;/div&gt;<br>   &lt;/div&gt;<br>&lt;/div&gt;</pre><h4>The Javascript</h4><pre>const hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];</pre><pre>function getTime(type, interval) {<br>    const d = new Date();<br>    let n;<br>    n = d.getHours();<br>    type === &quot;second&quot; &amp;&amp; (n = d.getSeconds());<br>    type === &quot;minute&quot; &amp;&amp; (n = d.getMinutes());<br>    type === &quot;hour&quot; &amp;&amp; (n = d.getHours());<br>    return type !== &quot;hour&quot; ?<br>        (n * 360) / interval :<br>        (n * 360) / interval + d.getMinutes() / 2;<br>}</pre><pre>function initialiseClock() {<br>    const timeTypes = [&quot;second&quot;, &quot;minute&quot;, &quot;hour&quot;];<br>    timeTypes.map(function(timeType) {<br>        document.querySelector(<br>            `.${timeType}`<br>        ).style.transform = `rotate(${getTime(<br>          timeType,<br>          timeType === &quot;hour&quot; ? 12 : 60<br>        )}deg)`;<br>    });<br>}<br>hours.map(function(hour) {<br>    const timeDiv = document.createElement(&quot;div&quot;);<br>    const timeSpan = document.createElement(&quot;span&quot;);<br>    const timeContent = document.createTextNode(`${hour}`);<br>    timeDiv.appendChild(timeSpan);<br>    timeSpan.appendChild(timeContent);<br>    timeDiv.setAttribute(&quot;class&quot;, &quot;numbers&quot;);<br>    timeDiv.style.transform = `rotate(${(360 / 12) * hour}deg)`;<br>    timeSpan.style.transform = `rotate(${-(360 / 12) * hour}deg)`;<br>    const circle = document.querySelector(&quot;.circle&quot;);<br>    circle.appendChild(timeDiv);<br>});</pre><pre>initialiseClock();<br>setInterval(function() {<br>    initialiseClock();<br>}, 1000);</pre><h4>The CSS</h4><pre>.container {<br>     display: flex;<br>     height: 100vh;<br>     justify-content: center;<br>     align-items: center;<br>}<br> .circle {<br>     width: 400px;<br>     height: 400px;<br>     border-radius: 200px;<br>     background: #404040;<br>     position: relative;<br>     box-shadow: 10px 10px 10px #999;<br>}<br> .circle:after {<br>     width: 15px;<br>     height: 15px;<br>     position: absolute;<br>     background: #aeaeae;<br>     content: &quot;&quot;;<br>     border-radius: 15px;<br>     left: calc(50% - 15px / 2);<br>     top: calc(50% - 15px / 2);<br>}<br> .hand {<br>     height: 180px;<br>     width: 2px;<br>     content: &quot;&quot;;<br>     position: absolute;<br>     top: 20px;<br>     left: calc(50% - 2px / 2);<br>     transform-origin: bottom;<br>     border-radius: 3px;<br>}<br> .second {<br>     background: #dedede;<br>}<br> .minute {<br>     background: #cecece;<br>     width: 5px;<br>     left: calc(50% - 5px / 2);<br>}<br> .hour {<br>     background: #bebebe;<br>     width: 8px;<br>     height: 120px;<br>     top: 80px;<br>     left: calc(50% - 8px / 2);<br>}<br> .numbers {<br>     font-family: &quot;Lucida Sans&quot;, &quot;Lucida Sans Regular&quot;, &quot;Lucida Grande&quot;, &quot;Lucida Sans Unicode&quot;, Geneva, Verdana, sans-serif;<br>     color: #eee;<br>     font-size: 16px;<br>     position: absolute;<br>     height: 200px;<br>     top: 0px;<br>     left: calc(50% - 20px / 2);<br>     width: 20px;<br>     text-align: center;<br>     transform-origin: bottom;<br>     box-sizing: border-box;<br>     padding-top: 5px;<br>}<br> .numbers span {<br>     position: absolute;<br>     left: 0;<br>}</pre><p>It will render something like so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*CVSohbzGQLM8zMUME4tvsw.png" /><figcaption>Clock Image</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a205b18039f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky little Javascript Questions]]></title>
            <link>https://iamclaudiajayne.medium.com/tricky-little-javascript-questions-c59442a7efe3?source=rss-8a0954e9b178------2</link>
            <guid isPermaLink="false">https://medium.com/p/c59442a7efe3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Claudia]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 20:55:28 GMT</pubDate>
            <atom:updated>2021-10-12T20:55:28.245Z</atom:updated>
            <content:encoded><![CDATA[<p>We always see those tricky little Javascript questions and I have just stumbled onto one that had me stumped for a little while. I decided to do a quick write-up about this. Hopefully, it will help someone understand it a bit better.</p><h4>The question — Part 1.</h4><blockquote>Given this JS snippet, what would print to the console?</blockquote><pre>let number;<br>for(var i=0; i&lt;5; i++){<br>    number = i;<br>    setTimeout(function(){<br>        console.log(number);<br>    },1000)<br>};</pre><p>Having a quick look at this, you might answer that it would just log out 0–4 to the console after 1 second.</p><p>That would be incorrect. It will log the number 4to the console 5 times. What? I’ll explain this soon, but first, let’s go to the next part of the question.</p><h4>The question — Part 2</h4><p>The code will change slightly to look like so. Notice that we have removed the number variable from the question and we are now logging i.</p><blockquote>Given this change, what will this log to the console?</blockquote><pre>for(var i=0; i&lt;5; i++){<br>    setTimeout(function(){<br>        console.log(i);<br>    },1000)<br>};</pre><p>0–4 after 1 second? Nope! This will log 5 to the console 5 times.</p><p>Brain explodes! Why? I will get to that soon. Let’s now change the code one more time. Let’s change to use let instead of var in the for-loop.</p><h4>The question — part 3</h4><blockquote>Given this final change,what do you think will log to the console?</blockquote><pre>for(let i=0; i&lt;5; i++){<br>    setTimeout(function(){<br>        console.log(i);<br>    },1000)<br>};</pre><p>That’s right! In this scenario, we will get 0–4 printed to the console.</p><h3>The explanation.</h3><p>To better explain what is happening, I will rewrite this using a while loop.</p><h4>Explanation — part 1</h4><p>Let’s analyse the first question. We had a declaration at play called number and we assigned the variablei to it. Rewriting it as a while loop, it will look like so. <em>The number declaration is set outside the loop and so the scope sits where it is originally declared. </em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let"><em>Read more about let</em></a></p><pre>var i=0;<br>let number;</pre><pre>while(i&lt;5){<br>    number=i;  <br>    setTimeout(function(){<br>        console.log(number);<br>    },1000);<br>    i++;<br>}</pre><p>If you look above, we are saying that <strong>while </strong><strong>i is less than 5</strong>, <em>which means </em><em>i needs to equal a maximum of 4</em>, we will set number to whatever i is at that point in time, we will then move the console.log to the browser’s queue and bring it back after a second, we can then increment i by 1.</p><p>If we were logging i, the answer would be 5 as in the final step of the loop, <strong>we still increment </strong><strong>i by 1</strong> . In this condition, however, we only allow number to equal i if i is less than 5. The maximum number that it could be is 4.<strong>This means we will print </strong><strong>4 to the console 5 times.</strong></p><h4>Explanation — part 2</h4><p>So what is happening here? Let’s look at the second example written out as a while loop.</p><pre>var i=0;</pre><pre>while(i&lt;5){<br>   setTimeout(function(){<br>        console.log(i);<br>    },1000);<br>    i++;<br>}</pre><p>Looking at the above function, we are seeing that initially our variable i equals 0. Cool beans. While i is less than 5 we want to increment i to be its value + 1;</p><p>So, while i=4,which is less than 5, our setTimeout is added to the browser’s queue to be run in one second.</p><p>We then have to run the next statement which is i++ so i is now equal to 5.</p><p>Finally, a second later, we bring the console.log(i) back into play and<strong> at this point the answer is </strong><strong>5 and of course, it runs 5 times.</strong></p><h4>Explanation — part 3</h4><p>In the last example, we are using let within the loop instead of var. This means that it is scoped to the block, which happens to be within the loop. The let declaration will cause there to be a distinct i for each iteration of the loop.</p><pre>let i=0;<br>while(i&lt;5){<br>    let scopedCopy = i; // creating a copy of i to mimic the loop<br>    setTimeout(function(){<br>        console.log(scopedCopy);<br>    },1000);<br>    i++;<br>}</pre><p>Every time this loops, the value ofscopedCopy will be specific for that loop itself. Think of it as unique copies of i.</p><p>Therefore, every time the loop runs, the version of i is different. It will log 0–4 to the console after a second</p><h3>How did they use to do it before let and const?</h3><p>If this is the case? How did they use to get around this before let and const were in the picture? The way around this would be to create a function that takes in i as an argument like so;</p><pre>function logUtil(i) {<br>    setTimeout(function() { <br>      console.log(i); <br>    }, 1000);<br>}<br><br>for (var i=1; i&lt;5; ++i){<br>    logUtil(i);<br>}</pre><p>Hope this makes sense! If you have any feedback or think there is an amendment to be made, please reach out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c59442a7efe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an Accordion without Javascript]]></title>
            <link>https://iamclaudiajayne.medium.com/creating-an-accordion-without-javascript-84abfb0705c4?source=rss-8a0954e9b178------2</link>
            <guid isPermaLink="false">https://medium.com/p/84abfb0705c4</guid>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[accordion]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[html-css]]></category>
            <dc:creator><![CDATA[Claudia]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 08:26:07 GMT</pubDate>
            <atom:updated>2022-10-27T21:32:21.639Z</atom:updated>
            <content:encoded><![CDATA[<p>Javascript is cool, but it looks like there are so many things we can do without it. One of these, believe it or not, is an accordion!</p><p>Simply use the details tag to create the accordion item. Within this, create a summary tag and put whatever text you would like for the title of the accordion.</p><p>Finally, add any other content and HTML tags you wish within the details section. Once expanded, by clicking on the rendered summary, these will appear.</p><pre>&lt;details&gt;<br>    &lt;summary&gt;The title of the accordion&lt;/summary&gt;<br>    &lt;p&gt;Anything else&lt;/p&gt;<br>    &lt;div&gt;Anything really &lt;span&gt;not kidding&lt;/span&gt;&lt;/div&gt;<br>&lt;/details&gt;</pre><p>If you add multiple details after each other, it will act like an accordion. One thing to note is when you open another item, it won’t automatically close the other one. You would need Javascript here if you require that functionality.</p><p>You can also have an initial item open by adding open to the details tag.</p><pre>&lt;details <strong>open</strong>&gt;<br>    &lt;summary&gt;The title of the accordion&lt;/summary&gt;<br>    &lt;p&gt;Anything else&lt;/p&gt;<br>    &lt;div&gt;Anything really &lt;span&gt;not kidding&lt;/span&gt;&lt;/div&gt;<br>&lt;/details&gt;</pre><p>Finally, you can style these all with some simple CSS. Here is an example I created earlier.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fstamfette%2Fembed%2Fpreview%2FqBXBQQE%3Fdefault-tabs%3Dhtml%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DqBXBQQE&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fstamfette%2Fpen%2FqBXBQQE&amp;image=https%3A%2F%2Fassets.codepen.io%2F2352326%2Finternal%2Fscreenshots%2Fpens%2FqBXBQQE.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dfalse%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1633924967%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/32dd7f6e6911ca7c92cec6f114faec4d/href">https://medium.com/media/32dd7f6e6911ca7c92cec6f114faec4d/href</a></iframe><p>Enjoy :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84abfb0705c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>