Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

How do i set a max limit to a counter of a onclick event?

$
0
0

I'm new to programming language javascript.

i keep looking everywhere for this answer and i found none that i can understand fully. i want to add a max limit to the counter i have and i don't understand how to go about doing.

  • How do i set a max limit to a counter of a onclick event?
  • do i need a if statement? if so how would i write it?
  • do i need to change anything on the html part of it? if so what?
  • if you can show me an example using my demo names of the function/variable ex.(goldClick, gold) it would help me tremendously.
  • if a secondary function/variable or further needs a name add silver and copper to the name so i know its different.,

	var gold = 0;
	function goldClick(){
		gold = gold + 1;
		document.getElementById("gold").innerHTML = gold;
		};
<button type="button" onclick="goldClick()">Gold</button><p>Gold:<a id="gold">0</a>/50</p>

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>