2

So this program when you click the mine button you have a chance to get bronze from it and you always get exp from it. once mining lv is past 10 you also get a chance for the mine to drop silver

screenshot

yesterday my values updated fine but today I'm getting this weird element once i press mine once.

Tried looking over my code for errors no luck.

Here is my JavaScript code:

var Bronzechance = 0.5;
var Silverchance = 0.25;
var Bronze = 0;
var Silver = 0;

function Miningaction() {
    if (MiningCexp < NextMaxMiningExp && Mininglv >= 1) {
        MiningCexp = MiningCexp + 1;
        if (Math.random() < Bronzechance)
            Bronze = Bronze + 1
        document.getElementById("Bronze").innerHTML = Bronze;
        document.getElementById("MiningCexp").innerHTML = MiningCexp;
    } 
    if(Mininglv >=10 && Mininglv <20){
        if (Math.random() < Silverchance){
            Silver = Silver + 1;
        }
        document.getElementById("Bronze").innerHTML = Bronze;
        document.getElementById("Silver").innerHTML = Silver;
        document.getElementById("MiningCexp").innerHTML = MiningCexp;

    } else {
        Mininglv = Mininglv + 1
        MiningCexp = 0
        Mining = Mining + 1
        NextMaxMiningExp = NextMaxMiningExp * 1.5;
        document.getElementById('MiningMexp').innerHTML = 
NextMaxMiningExp;
        document.getElementById('Mininglv').innerHTML = Mininglv;
        document.getElementById('MiningCexp').innerHTML = MiningCexp;
        document.getElementById('Mining').innerHTML = Mining;
    }
}

Html code:

           <br />
             Bronze: <span id="Bronze">0</span>
             <br />
             Silver: <span id="Silver">0</span>
             <br />
             Gold: <span id="Gold">0</span>
             <br />
             Diamond: <span id="Diamond">0</span>
             </div>



<div style="width: 300px;float:left; "  class=" col-sm-2">
  <h1> &nbsp; &nbsp; Mine </h1>
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  <button onclick="Miningaction()">
    <img src="cave.png" alt="cave" height="45" width="45">
  </button>

I expect my values to update normally, But the actual outcome i get

[object HTMLSpanElement]

next to silver instead of numbers.

Phil
  • 157,677
  • 23
  • 242
  • 245
tmanrocks994
  • 139
  • 7
  • It looks like this ~ [Do DOM tree elements with ids become global variables?](https://stackoverflow.com/questions/3434278/do-dom-tree-elements-with-ids-become-global-variables). To check, try changing `var Silver` to `var silverVal` or something like that. It's odd because adding `var Silver` should override the default _"id'd element to global variable"_ thing but who knows. – Phil May 30 '19 at 05:11
  • didnt do much. its like today after mabey adding a picture underfishing it broke – tmanrocks994 May 30 '19 at 05:20
  • na it wasn't the picture just tested that – tmanrocks994 May 30 '19 at 05:24
  • I'm sorry, I don't understand what you're saying at all. Please try changing the name of your variable from `Silver` to something else that doesn't exactly match the `id` of your `` element – Phil May 30 '19 at 05:25
  • @Phil how do i put screen shots in like that? all i have avalible is lightshot. i changed all the silvers to Silver1 cept the id one and i got this http://prntscr.com/nv8i8w – tmanrocks994 May 30 '19 at 05:28
  • The StackOverflow editor has an image upload / attach button. Also, if your code has changed, please [update the question](https://stackoverflow.com/posts/56371670/edit) to match – Phil May 30 '19 at 05:29
  • I fixed it. for some reason at the bottom of this javascipt file there was some random stuff. not sure how it got there. one was something with silver. I think i was going to make a way for silver to be hidden in game until mininglv was <10 but i forgot i added it to the bottom. ty for the help anyway – tmanrocks994 May 30 '19 at 05:34

0 Answers0