Roads or Rails explainer


Aim of the puzzle: Use a ternary operator in place of an if statement.

Walk through of solution: Use the first ternary as an example. Tap the area below where the car variable is defined. Tap the buttons to put car < train on this new line.

Make sure that train is highlighted and tap the ? : button to attach the ternary operator to the comparison.

Now, if the comparison is true, the code on the left side of the colon : will run. Add print('Drive a car') to the section after the ? but before the : symbol.

If the comparison is false, the code to the right of the : symbol will run. In the space after the : symbol, add a print() statement with the string ‘Buy train tickets’.

Sample code solution:
(Tap below to reveal)

var timeOffWork = 7;
var daysNeeded = 5;

timeOffWork > daysNeeded ? print('Go on vacation') : print('Go to work');

var train = 3;
var car = 2;

car < train ? print('Drive a car') : print('Buy train tickets');

Javascript Concepts: Variables, Ternary Operator, Comparison Operators

Grasshopper Concepts: print()


I tried everything like this and nothing mine looks exactly like the one underneath on yours :frowning_face:


Could you take a screenshot of your code and then share that here?



Uuuuh i did the code right and it didn’t work


Could you post a screenshot of your code? Are you getting any blue popup hints telling you to correct something?



@Cutieuni1 @SwiVVeRRz

I was looking at the puzzle again, and I found that there was some feedback that’s misleading. The ternary __?__:__ should have a comparison in the 1st blank, and then a print() in each of the other 2 blanks. But if the last print() is missing, the text says to add it to the middle blank – it should say to add it to the last blank. I’ll make sure this feedback gets fixed.

The solution in the original post should still work though. If you’re still having trouble, I could take a look at your code if you post it here.




@Grasshopper_Frankie this should also work but it doesn’t though it would be the easiest way to program it.


We can modify the checks to allow that solution as well. Thanks for the suggestion!