From e38d213bbf1080a506748c16483ad4306cfc20a1 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 18:09:21 +0530 Subject: [PATCH 1/5] Snippet to generate a random color code --- snippets/randomHexColorCode.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/randomHexColorCode.md diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md new file mode 100644 index 000000000..8e85d5781 --- /dev/null +++ b/snippets/randomHexColorCode.md @@ -0,0 +1,17 @@ +### randomHexColorCode + +Generates a random hecadecimal color code. + +Use `Math.random` to generate a random number and limit that number to fall in between 0 and 16 using `Math.floor`. Use the generated random number as index to access a character from 0 to F. Append it to `color` till the length is not `7`. + +```js +const randomHexColorCode = () => { + var color = '#'; + while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; + return color; +} + +// randomHexColorCode() -> "#e34155" +// randomHexColorCode() -> "#fd73a6" +// randomHexColorCode() -> "#4144c6" +``` \ No newline at end of file From f1ca6a6ffab026a9af2bb3b2b160dde31d8a74fa Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 18:10:36 +0530 Subject: [PATCH 2/5] Fixed indentation --- snippets/randomHexColorCode.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md index 8e85d5781..c234292ab 100644 --- a/snippets/randomHexColorCode.md +++ b/snippets/randomHexColorCode.md @@ -6,9 +6,9 @@ Use `Math.random` to generate a random number and limit that number to fall in b ```js const randomHexColorCode = () => { - var color = '#'; - while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; - return color; + var color = '#'; + while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; + return color; } // randomHexColorCode() -> "#e34155" From 77a6f93c278d7c32e5e1393ab0b8a97c93eb83e2 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 18:11:19 +0530 Subject: [PATCH 3/5] fixed typo --- snippets/randomHexColorCode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md index c234292ab..7d1b26d71 100644 --- a/snippets/randomHexColorCode.md +++ b/snippets/randomHexColorCode.md @@ -1,6 +1,6 @@ ### randomHexColorCode -Generates a random hecadecimal color code. +Generates a random hexadecimal color code. Use `Math.random` to generate a random number and limit that number to fall in between 0 and 16 using `Math.floor`. Use the generated random number as index to access a character from 0 to F. Append it to `color` till the length is not `7`. From 709756efe4d91cc7cb90d56d56cf4deb14f32b2d Mon Sep 17 00:00:00 2001 From: David Wu Date: Sun, 24 Dec 2017 14:23:45 +0100 Subject: [PATCH 4/5] Update randomHexColorCode.md --- snippets/randomHexColorCode.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md index 7d1b26d71..f77524ba7 100644 --- a/snippets/randomHexColorCode.md +++ b/snippets/randomHexColorCode.md @@ -10,8 +10,7 @@ const randomHexColorCode = () => { while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; return color; } - // randomHexColorCode() -> "#e34155" // randomHexColorCode() -> "#fd73a6" // randomHexColorCode() -> "#4144c6" -``` \ No newline at end of file +``` From b9d9ef716e1ed92838c8dbfb5e8fcfe8da45421d Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 18:57:44 +0530 Subject: [PATCH 5/5] Changed 'var' to 'let' --- snippets/randomHexColorCode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md index f77524ba7..18691a57a 100644 --- a/snippets/randomHexColorCode.md +++ b/snippets/randomHexColorCode.md @@ -6,7 +6,7 @@ Use `Math.random` to generate a random number and limit that number to fall in b ```js const randomHexColorCode = () => { - var color = '#'; + let color = '#'; while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)]; return color; }