How do I create an object generator that will create a random square that is a random colour, size and position on the page? I think I have set up all the parameters but I can't put it all together.
//Size Generator
function getRndInteger(min, max) {
return Math.floor(Math.random() * (200 - 50 + 1) ) + 50;
}
var getSize = getRndInteger(50, 200);
//Colour Generator
function getRandomColor() {
var letters = '0123456789ABCDEF';
var colour = '#';
for (var i = 0; i < 6; i++) {
colour += letters[Math.floor(Math.random() * 16)];
}
return colour;
}
var colour = getRandomColor();
//Position Generator
function getPosition(min, max) {
return Math.floor(Math.random() * (600 - 0 + 1) ) + 0;
}
var getX = getPosition(0, 600);
var getY = getPosition(0, 600);
//Square Generator
function squareGenerator() {
var div = document.createElement("square");
div.style.backgroundColor = colour;
div.style.left = getX + "px";
div.style.top = getY + "px";
div.style.height = getSize + "px";
div.style.width = getSize + "px";
}
Where I am stuck is how to get this to show up on the page.
squareGenerator()add this at the end of your scriptsquareisn't a valid HTML element?