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 trialadensaid
4,461 Pointswhat is wrong with my javascript file because every time I try to preview I got nothing except a title on the page?
Let’s Make Random Numbers --- is all i see on top-left corner of the page.
can anyone elaborate what I am missing? Thanks
4 Answers
Sergey Podgornyy
20,660 PointsFirst, please provide your code here
adensaid
4,461 Pointsthis is my javascript code:
function randomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; } var counter = 0; while ( counter < 10000 ) { var randNum = randomNumber(6); document.write(randNum + ' '); counter += 1; }
and this is my html code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Let’s Make Random Numbers</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Let’s Make Random Numbers</h1> <script src="video2-script.js"></script> </body> </html>
Sergey Podgornyy
20,660 PointsYou need to write you while
loop on proper way. Like in code below:
function randomNumber(upper) {
return Math.floor( Math.random() * upper ) + 1;
}
var counter = 0;
while ( counter < 10 ){
var randNum = randomNumber(6);
document.write(randNum + ' ');
counter++;
}
This code will generate 10 random numbers - https://jsfiddle.net/k53kxof1/
adensaid
4,461 PointsThanks Sergey, that helpful at the end!
Sergey Podgornyy
20,660 PointsYou are welcome ;)
adensaid
4,461 Pointshey Sergey!
Do you know how I can setup my own javascript environment so that I can code along with the instructor as he teaches the lessons?
Sergey Podgornyy
20,660 PointsYou can use treehouse Workspaces, but I suggest you to write all your code locally and preview it on browser. The best text editor for me is Sulime Text with Emmet plugin
jason chan
31,009 Pointsvar questions = [
{
question: 'How many states are in the United States?',
answer: 50
},
{
question: 'How many continents are there?',
answer: 7
},
{
question: 'How many legs does an insect have?',
answer: 6
}
];
var correctAnswers = 0;
var question;
var answer;
var response;
function print(message) {
document.write(message);
}
for (var i = 0; i < questions.length; i += 1) {
question = questions[i].question;
answer = questions[i].answer;
response = prompt(question);
response = parseInt(response);
if (response === answer) {
correctAnswers += 1;
}
}
html = "You got " + correctAnswers + " question(s) right."
print(html);
jag
18,266 Pointsjag
18,266 PointsHave you checked your browser's console? Other than that without showing your code it's hard to tell.