Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Mark Libario
Mark Libario
9,003 Points

CASINO CRAPS: Creating Loops and functions combined LOL What do you guys think?

So I played and did trial and error with functions and loops and I finally got it. What do you guys think of this? :)

every time a 4 or 10 rolls, I lose $100 everytime. If a seven rolls, I win 100$.

var rollDice;
var attempts = 0
var money = 0

function rollDieOne () {
  var dieOne = Math.floor ( Math.random () * 6) + 1;
  return dieOne

function rollDieTwo () {
  var dieTwo = Math.floor ( Math.random () * 6) + 1;
  return dieTwo

while (rollDice != 7 ) {
 var rollDice = (rollDieOne () + rollDieTwo ());
 alert("You rolled a "+ rollDice + ".");
  attempts += 1;

  if (rollDice == 4 || rollDice == 10) {
    money -= 100;


  if (rollDice ==7) {
    money += 100;


document.write("You rolled " + attempts + " times before crapping out.");

if (money >= 0) {
  document.write ("You won a total of $" + money + ".")
else {
  document.write ("You lost a total of $" + money + ".");

Strictly forward to the link of my favorite online casino http://njnodeposit.com They give deposit bonus code not only to strive your passion to the game for the first two rounds but occasionally surprise you with bonus dollars in your bank account. It happens because they want to keep you motivated and happy, so you will bring your friends to their website. As long as granting you bonuses are profitable, online casinos will give you bonuses. Most people don't think ahead, just of themselves, so they lose more than they can actually get. What else can I say? Good luck! and ofc you can check your alghoritm codes without your own deposit.