Share your repls and programming experiences

← Back to all posts
Dice!
JoshuaKing1 (66)

54 lines of Ruby code. A dice roller and guesser.

Comments
hotnewtop
theangryepicbanana (1688)

Do you know what the puts function is?

theangryepicbanana (1688)

also you can change rand(1...sides+1) to rand(1..sides)

JoshuaKing1 (66)

@theangryepicbanana Yeah. I just like to use print.

JoshuaKing1 (66)

@theangryepicbanana It might put a number like zero if it didn't have it.

theangryepicbanana (1688)

@JoshuaKing1 why would it print out 0? unless you are printing 0 or "0", it shouldn't

JoshuaKing1 (66)

@theangryepicbanana It won't. You can try to type in 0 every time and it will say that it's invalid.

JoshuaKing1 (66)

@theangryepicbanana Ruby does this weird thing so rand(1...7) will print out only 1, 2, 3, 4, 5, and 6. Not 7.

theangryepicbanana (1688)

@JoshuaKing1 that's because you are using ... instead of ... 1...7 does not include 7, but 1..7 does. look here for an example https://repl.it/@theangryepicbanana/TinyVioletredLibrary

EthanJustice (31)

Cool! I ended up getting the number right twice in a row!