no error on console, making little circles change colour on refresh

65 views Asked by At

I have been trying to complete a small exercise and I have it running in codepen but when I put it through sublime and open it in my browser it doesn't show anything! I have tried running it through JSHint, read over and over it. Would love if someone one could please take a moment to have a quick read through. ..This is what it's supposed to do.. http://codepen.io/hellojessicagraham/pen/Ropgob

var htmlDot = "";
var red;
var green;
var blue;
var rgbColor;


function colourSelect() {
    return Math.floor(Math.random() * 256 );
}

for(var i = 1; i<=100; i+=1) {
    red = colourSelect();
    green = colourSelect();
    blue = colourSelect();
    rgbColor = "rgb(" + red + "," + green + "," + blue + ")";
    htmlDot += "<div style=\"background-color:"+ rgbColor + " \"></div>";
}
document.write(htmlDot);

The HTML is as follows

<!doctype html>
<html>
<head>

    <link rel="stylesheet" href="main.css"> 
</head>
<body>

    <script src="script.js"></script>

</body>
</html>

CSS as follows

div{
  width: 50px;
  height: 50px;
  display: inline-block;
  border-radius: 50%;
  margin: 5px;

}

Thank you in advance

3

There are 3 answers

1
Quinox On

Since it seems to work with all the code on your html document, are you sure the links to your js/css files are correct ? Use the inspector in your navigator (F12) if you're not sure.

Edit : It's just working fine. Like Dejan said, your error is probably in your stylesheet.

var htmlDot = "";
var red;
var green;
var blue;
var rgbColor;


function colourSelect() {
 return Math.floor(Math.random() * 256 );
}

for(var i = 1; i<=100; i+=1) {
 red = colourSelect();
 green = colourSelect();
 blue = colourSelect();
 rgbColor = "rgb(" + red + "," + green + "," + blue + ")";
 htmlDot += "<div style=\"background-color:"+ rgbColor + " \"></div>";
}
document.write(htmlDot);
button {
  width:50px;
  height: 50px;
  border-radius: 50%;
  margin: 0px;
  display: inline-block;
}

div{
  width: 50px;
  height: 50px;
  display: inline-block;
  border-radius: 50%;
  margin: 5px;
}

1
Dejan On

Your javascript code is fine, all u forgot is the css of the div element. Your divs are all collapesed into oneand not displaying. Give them some love :D LIke in the link u posted they created circles with the folowing css.

.div {
  width: 50px;
  height: 50px;
  display: inline-block;
  border-radius: 50%;
  margin: 5px;
}
2
I_Al-thamary On

There is no

<body> 

Also, try to remove

  <!doctype html>

Actually, it works fine.Try to make sure about the path and the file name.

enter image description here