2
This is a very simple code where balls appear on the screen and one must click on them to "pop them". I’m learning the language, please understand the lack of skill in it. I would like to do a point counter to know how many of them the user clicked, but I don’t even know where to start. I tried to make a canvas where every time the user "misses" the balls (clicking off them), another one would appear, but, it didn’t work as it should so I removed it from the code. Also, I can’t make the balls appear faster as they’re eliminated, causing some kind of difficulty increase.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.bola {
width: 50px;
height: 50px;
border-radius: 25px;
position: absolute;
cursor: pointer;
}
</style>
<meta charset="UTF-8">
<title> Teste Jogo da Bolinha </title>
</head>
<script>
function cor_aleatoria(){
var hexadecimais = '0123456789ABCDEF';
cor = '#';
for (var i = 0; i < 6; i++){
cor = cor + hexadecimais[Math.floor(Math.random()*16)];
}
return cor;
}
function addBola(){
let bola = document.createElement("div");
bola.setAttribute("class","bola");
let pX = Math.floor(Math.random() * 500);
let pY = Math.floor(Math.random() * 500);
bola.setAttribute("style", "background-color:" + cor_aleatoria() + "; " + "left:" + pX + "px; top:" + pY+ "px; " + bola.setAttribute("onclick","estourar(this)"));
document.body.appendChild(bola);
}
function estourar(elemento){
document.body.removeChild(elemento);
}
function iniciar(){
setInterval(addBola, 1000);
}
</script>
<body onload="iniciar()">
</body>
</html>
From now on I thank you, any help will be welcome.
Telepathy huh. It’s not that I was responding exactly as has haha, with
% 5
and-= 100
. It looks sordid lol.– Isac
:D nossa! rsrs... But put there, surely your suggestion will be different in other aspects and worth as a suggestion too.
– Sam
It does not justify only differed on the timer, which had switched to
setTimeout
, the rest is all the same :D.– Isac