Javascript: Increasing the price of a item

The HTML fix the Raptor was talking about is a quick one. Just change this:

<button onclick="BuyItem">Buy</button> Cost: <span id="demo"></demo>

to this:

<button onclick="BuyItem">Buy</button> Cost: <span id="demo"></span>

it was the closing span tag at the end.

First thing is that you want to cache your DOM and localStorage values and elements. Both of those are expensive hits on performance.

You have to many quotes around your innerHTML assignment.

document.getElementById("hatch").innerHTML = "" + localStorage.Hatchcount + "";

You needs to do a quote on both sides of the value asignment.

document.getElementById("hatch").innerHTML = " + localStorage.Hatchcount + ";

P.S. I would still cache the DOM and localStorage stuff then evaluate against that.

Browse More Popular Posts

Leave a Comment