Travis build: 254

This commit is contained in:
Travis CI
2017-12-24 21:20:03 +00:00
parent 2ebb86f629
commit 4cf66fd758
2 changed files with 4 additions and 12 deletions

View File

@ -1440,12 +1440,8 @@ Omit the second argument to use the default regex.</p>
</code></pre>
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolorcode">randomHexColorCode</h3></div><div class="section double-padded">
<p>Generates a random hexadecimal color code.</p>
<p>Use <code>Math.random</code> to generate a random number and limit that number to fall in between 0 and 16 using <code>Math.floor</code>. Use the generated random number as index to access a character from 0 to F. Append it to <code>color</code> till the length is not <code>7</code>.</p>
<pre><code class="language-js">const randomHexColorCode = () =&gt; {
let color = '#';
while(color.length &lt; 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)];
return color;
}
<p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p>
<pre><code class="language-js">const randomHexColorCode = () =&gt; '#'+(Math.random()*0xFFFFFF&lt;&lt;0).toString(16);
// randomHexColorCode() -&gt; &quot;#e34155&quot;
// randomHexColorCode() -&gt; &quot;#fd73a6&quot;
// randomHexColorCode() -&gt; &quot;#4144c6&quot;