Loop help

hi! why i get this? if i dont use .pop everything ok.

1 Like

.pop() is a method for array, currentCard is not an array. Its a string (see line 6)

2 Likes

Thank you. Is it an array at global scope and a string at block scope?

1 Like

No, at line 1 you have the array called cards. you can use pop on this.

line 6 is where you take a random item of the array cards on line 1. Since the elements in the array are strings the variable on line 6 becomes a string.

because you are popping currentCard and not cards, pop() does not work.

If your goal is to clean out currentCard you could just reset it as currentCard = "" or if you do want currentCard to stay an array you would need to use append() instead of currentCard = cards[math.floor(....)]

Javascript is a bit sketchy like this. Just because you defined the variable before does not mean its type can’t change.

2 Likes

Can you do this: Yes. Do you currently have it? No. Should you do it? No, having two variables with the same name can be very confusing.

2 Likes