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 trialValeriya Voloshina
5,943 PointsMy code doesn't work
Hey guys! I posted my code below in this question. I don't see if it's any different from the one shown in the video yet mine does not seem to work. Could anyone help me?
Thanks!
function alertRandom() {
var randomNumber = Math.floor( Math.random() * 6 ) + 1;
alert(randomNumber);
}
alertRandom();
Marshall Vaughn
4,016 PointsSame issue for me. Code matches the video exactly. I duplicated the file structure locally and ran it, and it worked fine. Must be something wrong with the workspace.
2 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsTry Math.rand() rather than random. Watch that the syntax highlighting changes colour to indicate that you used the right method.
function alertRandom() {
var randomNumber = Math.floor( Math.rand() * 6 ) + 1;
alert(randomNumber);
}
alertRandom()
Jacob Mishkin
23,118 PointsI just ran your code in codepen, and it worked fine. I would check to see if you have your JS linked to the HTML.
Valeriya Voloshina
5,943 PointsThank you for taking interest! It was linked fine so must be something else then :/
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsedited code for formatting.