function checkPrice(afford){
var z = document.getElementById('man_cost').innerHTML;
var a = document.getElementById('mouse_cost').innerHTML;
var b = document.getElementById('farm_cost').innerHTML;
var c = document.getElementById('factory_cost').innerHTML;
a = parseInt(a);
b = parseInt(b);
c = parseInt(c);
z = parseInt(z);
if(afford == 'cannot'){
if(amount < z){
document.getElementById('upClick').style.opacity = '.5';
};
if(amount < a){
document.getElementById('upMouse').style.opacity = '.5';
};
if(amount < b){
document.getElementById('upFarm').style.opacity = '.5';
};
if(amount < c){
document.getElementById('upFactory').style.opacity = '.5';
};
}else if(afford == 'can'){
if(amount >= z){
document.getElementById('upClick').style.opacity = '1';
};
if(amount >= a){
document.getElementById('upMouse').style.opacity = '1';
};
if(amount >= b){
document.getElementById('upFarm').style.opacity = '1';
};
if(amount >= c){
document.getElementById('upFactory').style.opacity = '1';
};
};
return;
};
setInterval(checkPrice('can'),1000);
The setInterval
does not seem to be functioning. The price updates every second, but if the price reaches an affordable amount, the checkPrice
function does not execute the function and the effects do not take place as they should. However, when i call the setPrice
after user interaction, it works.