0
function skl() {
    var trct = 100;
    var amt = 100;
    while (amt == trct)
    {
        funk();
        amt += 50;
        trct = counttr();
    }
    console.log(amt, friendct);
};

Initially there are 100 <tr>s

funk() scrolls down to reveal 50 more <tr>s

counttr() counts the amount of TRs and returns the amount.

The point of the function is to scroll down until their is no more TRs. When there are no more <tr>s the function will still add 50 to amt but counttr() wont add 50, so when the for loop evaluates the numbers will no longer be equal to each other and the loop ends.

Edit - The loop only runs once and displays "100 150" meaning the value of trct didn't change.

5
  • A while statement would fit your needs better, I think. Commented Nov 11, 2012 at 15:39
  • You mean, it logs "150 100", not "100 150", right? If so, your counttr function reports an incorrect value. Either that, or funk fails to add more TRs. Commented Nov 11, 2012 at 15:41
  • The code for the counttr() function would be interesting. Commented Nov 11, 2012 at 15:43
  • 1
    Btw, it's TRs, not TR's (no apostrophe) Commented Nov 11, 2012 at 15:44
  • @ŠimeVidas if you would post an answer in regards to the variable not updating after iteration i will accept it as the answer. I'm assuming the variable update function needs to be delayed and thats what i will work on. thanks for debugging. Commented Nov 11, 2012 at 15:59

1 Answer 1

1

The second clause in a for-loop condition is tested on every iteration, and when it is no longer true, the loop is over.

Your for loop looks like this:

for (amt; amt == trct;)

If amt != trct after the first iteration, the for loop never runs a second time. You'll need to figure out why that's not the case. I would log three things a the end of the for loop, fro some visibility: amt, trct, and amt == trct.

It's possible that the counttr() function is returning something that you're not expecting

Sign up to request clarification or add additional context in comments.

2 Comments

That's not the issue. The issue is that trct didn't update on the first iteration.
I try the counttr function after it fails to run a second time and it displays the correct amount. I believe the problem may be the fact that i need to delay the iterations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.