Why in the exercise you have to enclose the ternary operator between brackets? Its not that its an array, right? An even more in the previous exercise the img is found by using “pics.kitty”, however with the ternary operator the final result would be “pics[kitty]”. Can someone please explain this?
It’s not coinToss but the entire expression, as it will result in keyword. It’s that keyword that will end up in the square brackets to lead us to pics[keyword].
@courseslayer16636
In your screenshot, you wrote coinToss === 'heads'
whereas in your next screenshot of the solution, you can see the correct comparison coinToss() === 'heads'
So, it isn’t a bug.
If you remember how we worked with the JSON-objects in earlier lessons, you can choose how to access the properties of the json-objects. By dot-notation or using the square brackets.
So “pics” here is an object, and we access its properties with the square brackets, like this:
pics[‘kitty’],
instead of maybe the more familiar way with the dot(.): pics.kitty
It might just look a bit confusing because we are at the same time using a ternary operator to determine what outcome should be printed