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 trialMichael Medvedskiy
4,588 PointsEndless Prompt doesn't let page-HTML refresh!
I was doing one challenge of the JS course. Quick review: there is an infinite prompt, which might put some info on the page. Only when I break the infinite loop, the whole info, that was supposed to be gradually adding to the page, instantly appears.
the code:
var message = '';
var student;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML += message;
}
function getRand256(){
return Math.floor(Math.random() * (256));
}
function getRandColor(){
return 'rgb(' +getRand256()+','+getRand256()+','+getRand256()+')';
}
function getStudent(sName){
for (var i = 0; i < students.length; i += 1) {
if(sName === students[i].name){
var lameP = '';
for(var N in students[i]){
lameP+="<p>"+ N +": "+ students[i][N] +"</p>";
//print("<p>"+ N +": "+ students[i][N] +"</p>");
}
print("<div style = 'border-bottom: 2px solid red; border-left:"+getRandColor()+" solid 2px; padding-left:60px'>"+lameP +"</div>")
}
}
}
while(true){
var name=prompt("Insert Stud name!");
if(name ==='quit' || name===null) break;
getStudent(name);
}
1 Answer
Adam Beer
11,314 Pointsreturn Math.floor((Math.random() * 256) + 1 );
If you fix this, what happened?
Michael Medvedskiy
4,588 PointsMichael Medvedskiy
4,588 PointsNothing of interest, really, because it will only affect color representation (as rgb(x,y,z) accepts (as x, y and z) numbers 0-255, which would ruin the code, as now we can get numbers 1-256, if we get a 256 even once, the program breaks (as we have Math. floor, and Math random returns [0;1) , we would never get 256 in my example)). So, this doesn't really help the topic.