Lesson 4 of 15

Conditionals

Conditionals

In F#, if/elif/else is an expression — it returns a value:

let score = 85
let grade = if score >= 90 then "A" elif score >= 80 then "B" else "C"
printfn $"{grade}"  // B

Use it directly as a function body:

let max a b = if a > b then a else b

Comparison & Logic

=, <>, <, >, <=, >=, &&, ||, not

Note: F# uses = for equality (not ==) and <> for inequality.

Your Task

Write a function sign that takes an integer and returns:

  • "positive" if greater than 0
  • "negative" if less than 0
  • "zero" if equal to 0
JS Transpiler loading...
Loading...
Click "Run" to execute your code.