Debería aleatorizar la ubicación de un círculo negro cuando se presiona, pero no puedo entender por qué no funciona.
function myFunction1(button) { var xPosition = math.floor(math.random() * 101) + '%'; button.style.top = xPosition; var yPosition = math.floor(math.random() * 101) + '%'; button.style.left = yPosition; } .circle { width: 100px; height: 100px; background-color: red; border-radius: 50%; } .black { background-color: black; } <button type="button" class="black circle" onclick="myFunction1(this)"></button>Prueba esto:
Cambiar matemáticas... a Matemáticas ...
Y agrega esto a css:
.circle { ... position: fixed; }Como esto:
function myFunction1(button) { var xPosition = Math.floor(Math.random() * 101) + '%'; button.style.top = xPosition; var yPosition = Math.floor(Math.random() * 101) + '%'; button.style.left = yPosition; } .circle { width: 100px; height: 100px; background-color: red; border-radius: 50%; position: fixed; } .black { background-color: black; } <button type="button" class="black circle" onclick="myFunction1(this)"></button>