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
Steven Cousineau2,563 Points
if statement will not execute!
Hello everyone, I'm kinda confused at the moment why my code will not execute the if statement, I've tryed the code in another editor and the same result. I have it logging the randomNumber in the console to make sure i can get the right answer to test as you can see. I would appreciate any input and I thank you!
_My workspace code here->https://w.trhou.se/9pmqp7wbwg
Michael Lambert6,286 Points
It seems that the random number can't return a number to a variable and print a number to the console in one statement. The variable randomNumber never receives the random number which is why the 'if' part isn't working. Don't know how you could achieve both at the same time in this manner.
You're problem seems to be: var randomNumber = console.log(Math.floor(Math.random() * 6) + 1); The correct way is to just make it this: (Math.floor(Math.random() * 6) + 1);