Solució botons-celestials-jquery
De wikiserver
Fitxer HTML:
<html>
<head>
<title>Botons Celestials</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript" src="js/ExBotonsCelestials.js"></script>
</head>
<body>
<div id="contenido"></div>
</body>
</html>
Fitxer js:
$(function(){
$('<input type="button" class="angelet" value="angel"/>').appendTo('#contenido');
$('#contenido').append('<input type="button" class="dimoni" value="dimoniet"/>');
$('.dimoni:last').on("click", function(){dimoniet();});
$('.angelet:last').click(function(){angelet();});
});
function angelet(){
var numBotones = Math.floor(Math.random()*10)+1;
for(var i=0; i<numBotones;i++){
if(Math.round(Math.random())){
$('<input type="button" class="angelet" value="angelet"/>').appendTo('#contenido');
$('.angelet:last').on("click", function(){angelet();});
}
else{
$('#contenido').append('<input type="button" class="dimoni" value="dimoniet"/>');
$('.dimoni:last').on("click", function(){dimoniet();});
}
}
}
function dimoniet(){
var numBotones = Math.floor(Math.random()*20)+1;
for(var i=0; i<numBotones;i++){
if(Math.round(Math.random())){
$("#contenido").children().remove(".angelet:last");
}
else{
$("#contenido").children(".dimoni:last").remove();
}
}
}