<?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: Tarun D</title>
    <description>The latest articles on DEV Community by Tarun D (@tarun080698).</description>
    <link>https://dev.to/tarun080698</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%2F655591%2F56e0680d-c812-40f0-8f4d-c7195e1150c6.jpeg</url>
      <title>DEV Community: Tarun D</title>
      <link>https://dev.to/tarun080698</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarun080698"/>
    <language>en</language>
    <item>
      <title>Generate Random Colors using JavaScript</title>
      <dc:creator>Tarun D</dc:creator>
      <pubDate>Sun, 19 Dec 2021 10:05:32 +0000</pubDate>
      <link>https://dev.to/tarun080698/generate-random-colors-using-javascript-d95</link>
      <guid>https://dev.to/tarun080698/generate-random-colors-using-javascript-d95</guid>
      <description>&lt;p&gt;Suppose if you want to generate a random colour for any element in your HTML and want to use that colour in real-time. &lt;/p&gt;

&lt;p&gt;The above code snippet will help you do the needful. This code also has a feature to generate different colours in &lt;strong&gt;rgb(???,???,???)&lt;/strong&gt; format in a time frame say &lt;em&gt;1-second&lt;/em&gt; or &lt;em&gt;n seconds&lt;/em&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;

  &amp;lt;body&amp;gt;&amp;lt;button class="btn"&amp;gt;Look how the colors are changing&amp;lt;/button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const randomNumber = (min, max) =&amp;gt;
  Math.floor(Math.random() * (max - min + 1) + min);

const randomColor = () =&amp;gt;
  `rgb(${randomNumber(0, 255)}, ${randomNumber(0, 255)}, ${randomNumber(
    0,
    255
  )})`;

const btn = document.querySelector('.btn');

const assignRandom = () =&amp;gt; {
  btn.style.color = randomColor();
  btn.style.backgroundColor = randomColor();
};

assignRandom();
setInterval(assignRandom, 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.btn {
  display: inline-block;
  font-size: 20px;
  font-family: inherit;
  font-weight: 500;
  border: none;
  padding: 10px 20px;
  border-radius: 10rem;
  cursor: pointer;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Result will be something like this&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--agrDqnVU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmaxfho47kptoroh2okj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--agrDqnVU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmaxfho47kptoroh2okj.gif" alt="Image description" width="500" height="88"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I hope this will help someone.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. This is my first post, hoping for some feedback.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
