This forum is now read-only. Please use our new forums at discuss.codecademy.com.

239 points
545bb0cd52f86378c1000086_30499918
Submitted by
Max
over 4 years ago

Error? ( number 6)

Every time i get: "Oops, try again. There was a problem with your syntax."

My Code;

// pick a random number between 1 and 6 for our roll of the die
var die1 = Math.floor(Math.random()6 + 1);
var die2 = Math.floor(Math.random()6 + 1);
var score;
// This time if either die roll is 1 then score should be 0
if(die1 === 1 || die2 === 1) {
score = 0;
}
else {
// here we need to check if there are doubles. If so, score should be
// double the sum of the two dice
if(die1 === die2)
score = 2*(die1 + die2);

else
score = die1+die2;
};
console.log("You rolled a "+die1+" and a "+die2+" for a score of "+score);


0 votes

permalink

Try this code:

          var die1 = Math.floor(Math.random()*6 + 1);
          var die2 = Math.floor(Math.random()*6 + 1);
          var score;
          if(die1===1 ||die2===1){
           score=0;
           }
          else {
                   if(die1===die2){
                   score=2*(die1+die2);
                    }
                   else{
                          score=die1+die2;
                       }
                    }

   console.log("You rolled a "+die1+" and a "+die2+" for a score of "+score);

1490 points
Picture
Submitted by
Kavita Tiwari
over 4 years ago

1 Comment

545bb0cd52f86378c1000086_30499918 Max over 4 years ago

Thanks!