JSFiddle - React, Tailwind, and code Playground
by thelifeisyours
HTML
<input class="tree" type="button" numHits="" value="Hit the tree!"></input><span></span>
JavaScript
$(document).ready(function(){
var max = 10,
min = 3,
numHits;
function getNum(num) {
num = Math.floor(Math.random() * (max - min + 1)) + min;
console.log('asigned num = '+num);
return num;
}
$(this).on('click', '.tree', function(){
var $this = $(this);
numHits = $this.attr('numHits');
if($this.attr('numHits') === undefined || $this.attr('numHits') <= 0 ){
numHits = getNum();
$this.attr('numHits',numHits);
$this.next().html(numHits);
console.log(numHits);
}else if($this.attr('numHits') == 0){
$this.next.remove();
$this.remove();
}else if($this.attr('numHits') >= 1){
numHits--;
$this.attr('numHits',numHits);
$this.next().html(numHits);
console.log(numHits);
}
});
});