program a basic clicker game javascript code example
Example: JavaScript basic clicker game
var incrementInterval = 10
var lemons = 0.0
var lemonsPerClick = 1.0
var lemonsPerIncrement = 0.0
function addLemons() {
lemons += lemonsPerClick
updateLemons()
}
function updateLemons() {
document.getElementById("lemonCounter").innerHTML = `Lemons: ${Math.floor(lemons)}`
}
function incrementValue(target) {
return target / (1000 / (incrementInterval * 10))
}
setInterval(function() {
lemons += incrementValue(lemonsPerIncrement)
updateLemons()
}, incrementInterval * 10)