Ask coding questions

← Back to all posts
How do i make a command like HowGay
Purexity (0)

Ive been trying to make a command that picks a random percent 1-100 for a command like HowGay in dank memer. Can anyone help me?

Comments
hotnewtop
Coder100 (18207)
console.log(`You are ${Math.floor(Math.random() * 100)}% gay.`);

Explanation
Math.floor is a function that rounds down.
Math.random is a function that returns a random decimal 0-1

We multiply by 100 to extend it to a number that returns 0-100

xxpertHacker (930)

@Coder100 Isn't that off by one?
Math.random returns [0, 1) or (0, 1] (I don't remember which one), but not [0, 1].

Coder100 (18207)

Yeah ur right ig
Math.floor(Math.random() * 101))
@xxpertHacker