Sample finish issue?


s = "loop_compus"

sample s, finish: 0.75
sleep 8
sample s , finish: 0.75/3
sleep 8
sample s , finish: 3/4

Which line do you think won’t work as expected ?

This might not be obvious unless you’re aware of the way Ruby handles division :slight_smile:
In Ruby, if you divide two integer numbers, the result also becomes an integer.
So here, since 3 / 4 is calculated as 0.75 but the numbers involved are both integers, a result of 0 is returned.
To make it return the desired result instead, at least one of the numbers needs to eg. be a float:
3/4.0 will work, as will 3.0/4, or you can use .to_f on one of them, etc.

1 Like

yep @ethancrawford i guessed it was about this but try to explain this to 13-14 old pupils :slight_smile: good luck. It’s the chance to introduce variable types.