I have been set an assignment to create my own simplified version of the game cookie clicker (http://orteil.dashnet.org/cookieclicker/). I have managed to get almost everything working with the exception of one thing, I'm trying to print an alert to say that in order to buy an upgrade, you first need X amounts more rashers of bacon, (the player increases their amount of rashers through clicking on the image of bacon).
These are my current declared variables:
<script>
var RPS=0;
var RPC=1;
var bacon=0;
var RPCPrice=50;
var RPSPrice=50;
</script>
With RPS meaning the current number of rashers the player is getting per second, RPC meaning the current number of rashers the player is getting per click, and RPC/RPS Price being the cost in rashers of the next upgrade.
I have managed to get an alert to say the correct number of rashers a player is away from the price of the next upgrade by using:
document.getElementById('errors').innerHTML="You can't afford this RPC upgrade, you need " + (RPCPrice-bacon + " more rashers!");
However was wondering if there was a more efficient way to do this by declaring a variable suchas:
var neededRPS=Math.round(RPSPrice-bacon);
and then changing the alert too:
document.getElementById('errors').innerHTML="You can't afford this RPS upgrade, you need " + neededRPS + " more rashers!");
however this does not seem to work.
Any help would be much appreciated, or if anybody knows of any simpler way to do this please enlighten me! I am a javascript newbie so apologies in advance if this has a very simple fix i have missed.
Cheers