0

In example 1, running that results in line 4 being executed and then skipping right over line 5. In example 2, changing line 4 to refer to the actual value rather than an array allows line 5 to be executed.

What can I do to make example 1 work properly? And why does example 2 work and not example 1?

I've used the same for loop in another instance, with a different array, that worked perfectly. So perhaps it's the array itself that's the problem?

1.

var temp2 = rightbarcoderead(i);

        for (i = 0; i < 10; i++) {
            if (temp2 === righteven[i]) {
                rightbarcode += i
            }

2.

var temp2 = "100110";

        for (i = 0; i < 10; i++) {
            if (temp2 === righteven[i]) {
                rightbarcode += i
            }
1
  • What does rightbarcoderead(i) return you (try console.log(temp2))? Why are you using i there and then again for the for loop? Why do you think the array is the issue here? Couldn't you just replace this whole loop with righteven.indexOf(temp2)? Commented Mar 27, 2017 at 16:02

1 Answer 1

1

From the information provided the only thing we know for sure is that in example 1 temp2 is not set with the expected value 100110.

This may be due to i being undefined when you call

var temp2 = rightbarcoderead(i);

or i set with the wrong value or, again, rightbarcoderead() function not returning the expected result with the given i parameter.

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

Comments

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.