'innerHTML' Undefined

Asked

Viewed 170 times

1

I need help, I can’t make it work.

var valu=document.getElementsByClassName("user-coins-value middle-block")[0];
var yesno=confirm("You have access key ?");
if(yesno==true)
    {
    var enter_key=prompt("Enter access key",'Example: 43ML9923');
    if(enter_key==".")
        {
        alert("OK\nNotice in 5 seconds!");
        setTimeout(function()
            {
            var enter_coins=prompt("Enter value of coins",'Min: 1000, Max: 75000');
            var timer=setInterval(function()
                {
                var i=document.getElementsByClassName("user-coins-value middle-block")[0].innerHTML;
                i++;
                valu.innerHTML=i++;
                if(valu.innerHTML==enter_coins)
                    {
                    clearInterval(timer);
                    alert("It's all\nGood buy")
                }
            }
            ,25)
        }
        ,5000)
    }
    else
        {
        alert("Wrong ACESS KEY")
    }
}
  • Where you are starting/declaring this variable i?

  • I declared above the first line, but forgot to copy it here.

  • I tested your code and it did not fail. Where is this error? Oh, I was in doubt about the i++, you wanted to do what there? start with 0 and increment each interval?

  • Yes, at each interval you are increasing the value. You are giving error here '' var i=Document.getElementsByClassName("user-Coins-value Middle-block")[0]. innerHTML; ''

1 answer

1

Your code is working perfectly, what you have to make sure is that the HTML does not contain any space or other character type that is not number inside. Example: if your code looks like this:

  <div class="user-coins-value middle-block">
     5
  </div>

Change to:

 <div class="user-coins-value middle-block">5</div>
  • He’s right, but he keeps making the mistake after entering the value of 1000 to 75000.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.