Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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);