Note: migrating question from outside freecodecamp, because I’m having a hard time understanding it.
when I run:
var html = '';
var red;
var green;
var blue;`
var rgbColor;
for(var i = 0; i < 4; i++) {
red = Math.floor(Math.random() * 256 );
green = Math.floor(Math.random() * 256 );
blue = Math.floor(Math.random() * 256 );
rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')';
html += '<div style="background-color:' + rgbColor + '"></div>';
document.write(html);
}
I get 10 divs with 10 random colors.
But when I change it to:
var html = '';
var red;
var green;
var blue;
var rgbColor;
for(var i = 0; i < 4; i++) {
red = Math.floor(Math.random() * 256 );
green = Math.floor(Math.random() * 256 );
blue = Math.floor(Math.random() * 256 );
rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')';
html += '<div style="background-color:' + rgbColor + '"></div>';
}
document.write(html);
Hi, sorry, not an answer: I’ve just cleaned your code up. You don’t need the backticks at the start and end of each line, you only need the three at the start and end of the whole block. I’ve removed those single backticks on each line: just makes things easier to read and it means the code can be copied and pasted somewhere to check it.
You should be able to edit the post: if you click the … at the bottom one of the options should be a little pencil icon: I’m not sure what all the constraints on it are though (there’s a window of time when you’re allowed to edit), bit you should be able to modify your post.