0

Ok, I'm taking the JavaFX with Passion course and have an issue that I can't seem to figure out.

It's similar to this question -

Why doesn't this "binding" code work as expected in JavaFX?

def numbers = [1..10];
var currentNumber = 0;    

for (currentNumber in numbers){
var evenOrOdd = bind if (numbers[currentNumber] mod 2 == 0)
    "----{numbers[currentNumber]} is an even number"
    else "----{numbers[currentNumber]} is an odd number";
println("{evenOrOdd}");
}

and my output -

----2 is an even number
----3 is an odd number
----4 is an even number
----5 is an odd number
----6 is an even number
----7 is an odd number
----8 is an even number
----9 is an odd number
----10 is an even number
----0 is an even number

The issue I'm having is that it 'looks' to run right except it doesn't display 1 as an odd number and then it adds a 0 after the 10. I spent some time stepping through the program and can't seem to find out how/why it's doing this.

I can get it to run great without any binding so not sure if that's what's causing my problem.

Any ideas/thoughts?

~Allen

1
  • Why doesn't your code look like java? Commented Dec 8, 2020 at 0:38

1 Answer 1

3

currentNumber is one of the elements of numbers, not the index

var evenOrOdd = bind if (currentNumber mod 2 == 0)
    "----{currentNumber} is an even number"
    else "----{currentNumber} is an odd number";
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, figured that out this morning. Man, that's what happens when you try to code while tired. :D Thanks for the help!

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.