javascript basic clicker game

Solutions on MaxInterview for javascript basic clicker game by the best coders in the world

showing results for - "javascript basic clicker game"
Eden
23 Sep 2016
1//Basic variables (the currency in this example is lemons)
2var incrementInterval = 10 //This is done so the code in the setInterval function runs 10 times per second
3var lemons = 0.0
4var lemonsPerClick = 1.0
5var lemonsPerIncrement = 0.0
6
7//Function for clicking to get lemons
8function addLemons() {
9	lemons += lemonsPerClick
10	updateLemons()
11}
12
13//Function for updating the lemon counter
14function updateLemons() {
15	document.getElementById("lemonCounter").innerHTML = `Lemons: ${Math.floor(lemons)}`
16}
17
18//Function that returns the target's value if it were to be divided into 1 second relative to milleseconds
19function incrementValue(target) {
20	return target / (1000 / (incrementInterval * 10)) //Target divided by one second
21}
22
23//Function that runs the following code repeatedly (function, milleseconds before running again)
24setInterval(function() {
25	lemons += incrementValue(lemonsPerIncrement)
26	updateLemons()
27}, incrementInterval * 10)