If
Last updated
Last updated
if
is an expression.
All if
expressions start with the keyword if
, followed by a condition.
It’s also worth noting that the condition in this code must be a bool
. If the condition isn’t a bool
, we’ll get an error.
Because if
is an expression, we can use it on the right side of a let
statement to assign the outcome to a variable
Reference:
This exercise is simple, we just need to add if
expression that checks which variable is bigger in the function bigger
.
Because if
is an expression we can just type a
and b
and it will serve as returned value.
In this example we need to take a look at the predefined testcases.
Test1 - yummy_food
: : expect string "Yummy!"
if the argument is "strawberry"
.
Test2 - neutral_food
: expect string "I guess I can eat that."
if the argument is "potato"
.
Test3 - default_disliked_food
: expect string "broccoli"
, "gummy bears"
, or "literally anything"
.
We are missing two case in the picky_eater
function.
So lets add potato
using else if
and the rest can go to else
block.
Because if
is an expression, we can use it on the right side of a let
statement to assign the outcome to a variable
In this case we just need make sure that the returned values in the identifier
if expression to have the same types.
Make 0
as substitute of "unknown"
value.