Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe1bc4f

Browse files
New: Random generate number
1 parent b871d11 commit fe1bc4f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎basic/generate_number.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function getRandomInt(max) {
2+
return Math.floor(Math.random() * max);
3+
}
4+
5+
console.log(getRandomInt(3));
6+
// Expected output: 0, 1 or 2
7+
8+
console.log(getRandomInt(1));
9+
// Expected output: 0
10+
11+
console.log(Math.random());
12+
// Expected output: a number from 0 to <1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /