javascript game help pls [closed] Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of javascript game help pls [closed] without wasting too much if your time.

The question is published on by Tutorial Guruji team.

The game is able to get unlimited money by pressing the button. How do I prevent this?

var workbard = document.getElementById("workbar");
function work() {
  var zaman = setInterval(function () {
    workbard.value +=1;
    if (workbard.value == 10) {
      workbard.value -=11;
      workbard.style.visibility = 'hidden'
      clearInterval(zaman);
      money = money +=5;
      experience = experience +=10;
      document.getElementById("para").innerHTML= ":" +money;
      document.getElementById("exp").innerHTML=":" +experience;
    }
<progress id="workbar" alue="0" max="10"></progress>
<button type ="button"id="workb2"onclick="work(),document.getElementById('workbar').style.visibility='visible'">Work</button>

Answer

you need to initialize some variables, add a limit and then use an if statement

var workbard = document.getElementById("workbar");
var money = 0;
var experience=0;
var limit = 30;
function work() {
  var zaman = setInterval(function () {
    workbard.value +=1;
    if (workbard.value == 10) {
      workbard.value -=11;
      workbard.style.visibility = 'hidden'
      clearInterval(zaman);
      money = money +=5;
      if(money > limit)money = limit;
      experience = experience +=10;
      document.getElementById("para").innerHTML= ":" +money;
      document.getElementById("exp").innerHTML=":" +experience;
    }})}
<progress id="workbar" alue="0" max="10"></progress>
<button type ="button"id="workb2"onclick="work(),document.getElementById('workbar').style.visibility='visible'">Work</button>

<div id='para'></div>
<div id='exp'></div>
We are here to answer your question about javascript game help pls [closed] - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji