user2555269
user2555269

Reputation:

Why won't my if() statement work? Javascript

I can't seem to figure out why this if() statement works, any ideas why?

Game.Items = {autoClickers: [50, 1, "Gives you one click every second, cost 50 clicks."]};
Game.UsersItems = {itemAutoClickers: [0], itemClickingTeam: [0]};

if(Game.UsersItems.itemAutoClickers > 0) {
    setInterval(function() {
         Game.Clicks = Game.Clicks + Game.Items.autoClickers[1];
         getElement('clicks').innerText = "Clicks: "+Game.Clicks;
         document.title = "Pointer Clicker | Clicks: "+Game.Clicks;
    }, 1000);
} 

Upvotes: -2

Views: 124

Answers (2)

dm03514
dm03514

Reputation: 55972

are you trying to check if the number of items in itemAutoClickers array is greater than 0 or if the value of the first item is greater than 0?

Game.UsersItems.itemAutoClickers.length > 0

or

Game.UsersItems.itemAutoClickers[0] > 0

Upvotes: 1

voigtan
voigtan

Reputation: 9031

Game.UserItems.itemAutoClickers is an array is it its .length you want to check?

or is it the value of the first index of your array?

Game.UserItems.itemAutoClickers[0] in that case

Upvotes: 1

Related Questions