I'm new to coding, and I'm trying to create three different shapes by accident after clicking - circle, square and triangle. I got my code to work with randomly creating a circle or square, but the triangle is always inside the square or circle element and never by itself. How to make so that instead of a square or a circle with a triangle, a circus, square or triangle appears inside?
<div id="shape1"></div>
CSS style (I tried to set the triangle as a “base” shape.
#shape1 {
width: 0;
height: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 200px solid #2f2f2f;
font-size: 0;
line-height: 0;
}
main.js
setTimeout(function () {
if (Math.random()<=0.3){
document.getElementById("shape1").style.borderRadius="50%";
}
else if (Math.random()<=0.6){
document.getElementById("shape1").style.borderRadius="0";
}
else {
document.getElementById("shape1").style = this.self;
}
Any help would be greatly appreciated. The best of coding for you.
source
share