Files
30-seconds-of-code/snippets/randomBoolean.md
2022-02-13 19:04:17 +02:00

373 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
Random boolean value math,random,beginner 2021-01-20T16:20:08+02:00 2021-01-20T16:20:08+02:00

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.
const randomBoolean = () => Math.random() >= 0.5;
randomBoolean(); // true