From 3cba520c4b27c432685845f7b183330bba7069a6 Mon Sep 17 00:00:00 2001 From: Chalarangelo Date: Wed, 20 Jan 2021 16:20:08 +0200 Subject: [PATCH] Add randomBoolean --- snippets/randomBoolean.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 snippets/randomBoolean.md diff --git a/snippets/randomBoolean.md b/snippets/randomBoolean.md new file mode 100644 index 000000000..f382f9a09 --- /dev/null +++ b/snippets/randomBoolean.md @@ -0,0 +1,16 @@ +--- +title: randomBoolean +tags: math,random,beginner +--- + +Generates a random boolean value. + +- Use `Math.random()` to generate a random number and check if it is greater than or equal to `0.5`. + +```js +const randomBoolean = () => Math.random() >= 0.5; +``` + +```js +randomBoolean(); // true +```