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!
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

Elvis Reinis Zeltītis
1,925 Pointstimers updating math.random
Hello, and thanks in advance!
Basically, I am trying to generate numbers that are changed every half second, theres really no need for it, im just playing around with some already made functions and im trying to figure them out. I've got some results already, I've managed to get the numbers be changed on the very beggining when the website is opened but nothing else!
And im having another issue that im having trouble figuring out. Im trying to use the function in the console but it doesnt work!
var timer = setInterval( theMatrix, 1000 );
function theMatrix() {
var matrix = Math.floor(Math.random()*123456789)+1;
document.write("<p>"+ matrix +"</p>" );
}
theMatrix();
4 Answers

Jennifer Nordell
Treehouse TeacherI sincerely wish I could. But here's the problem. This code runs in both Firefox and Chrome for me. I ran it and got a never-ending scrolling page of randomly generated numbers I can even access the
theMatrix
function. So, I'm at a loss as to why it's not working for you. What browser are you using? And have you tried clearing the cache?

Elvis Reinis Zeltītis
1,925 PointsJennifer Nordell Sorry to bring you to this, but I've seen you answer many questions. I thought maybe you could help me out abit? :)
Thanks in advance!

Elvis Reinis Zeltītis
1,925 PointsThanks for lightning fast reply ^^
The browser im using is Mozilla, and I've just cleared the cache, which didnt solve the problem. I didnt get my screen filled but it got yours, so I guess I should move this outside of the timer somehow?
document.write("<p>"+ matrix +"</p>" );
What Im trying to achive is something like matrix. I want the numbers to change without changing theyr position ofcouse. Its nothing that I need for anything at the moment, im just trying to do some fun stuff with javascript right now, while trying to understand more functions :)
-- Edit I guess I should download Google Chrome, but it doesnt change the fact that I would like it to run on multiple browsers ^^

Jennifer Nordell
Treehouse TeacherYou're correct, it doesn't fill up firefox. I must've checked Chrome twice on accident. But it does fill up Chrome. The problem is that you're using document.write which will continuously add to the document. I believe what you need to do is create an object where you can add an innerHTML.

Elvis Reinis Zeltītis
1,925 PointsJennifer Nordell Well thanks for all, Im done for today, I'll try to sort this out tomorrow whith a clear head ^^ Still cant beleive that simple thing like this turned into madness. Just because of how complex it turned out I am willing to make it work now! :)
And thanks again! :)