Code shows up with red error message - still get green approval?


#1

Ruby 3. Control Flow in Ruby: elsif

When submitting code, I get red error message in right screen. But still get approval green tic and am allowed to move on to next exercise?? Why, if the code is wrong?? Got that situation before. Thanks for enlightening me. K

My code:
if a < b
    puts "This gets printed because a is smaller than b"
elsif a > b
    puts "a is greater than y"
else 
    prints "a equals b"
end

Note: have put in third string with prints (instead of puts) on purpose, to see if that works, too. Does not seem to be the problem as error info points to variable error.

Error message I get:
undefined local variable or method `a' for #<Context:0xa859e4>


#2

The reason I think of now,
You haven't defined the a and b variables and directly used it.
probably CC have some garbage values so even you have not defined a and b, It lets you pass.

another thing to note ?
prints "a equals b"

You meant print ? (even the code lets us go ahead with it)


#3

Hi greentreemee,

Thanks a lot for your answer. I had a notion it might have to do with variable definition. (absolute beginner :slight_smile: )

“prints” is a typo, thanks.

What annoys me a bit is that it is difficult to learn something where every character matters but you get away with typing mistakes and are asked to continue.

Thanks a lot!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.