Skip to content

Commit 2dca1c1

Browse files
added random boolean generator
1 parent 1312623 commit 2dca1c1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
| Problem - 13 | Write a function to check if an object is empty or not in javaScript? |
1818
| Problem - 14 | Write a function to remove array element based on object property? |
1919
| Problem - 15 | Get the Middle Character |
20-
<!-- | Problem - 15 | | -->
20+
| Problem - 16 | Generate random boolean in JavaScript |
21+
<!-- | Problem - 16 | | -->

Diff for: problem-16.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// get random boolean (true/ false)
2+
3+
console.log(Math.random() >= 0.5);
4+
console.log(Math.random() < 0.1); //10% probability of getting true
5+
console.log(Math.random() < 0.4); //40% probability of getting true
6+
console.log(Math.random() < 0.5); //50% probability of getting true
7+
console.log(Math.random() < 0.8); //80% probability of getting true
8+
console.log(Math.random() < 0.9); //90% probability of getting true

0 commit comments

Comments
 (0)