From the course: ReasonML: First Look

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Solution: Quadratic formula

Solution: Quadratic formula - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

Solution: Quadratic formula

(upbeat music) - [Instructor] Here's the solution to the quadratic equation problem using if and else if. I've used the unicode for superscript two when displaying the equation. This line binds a local variable discriminant to the value of b squared minus 4ac, and then I use a chain or if and else ifs to determine the correct solutions and the output. Here's what it looks like when we run it. If you decided to solve this challenge using the switch expression, you may have written something like this. This time we switch on discriminant, and the first two cases use guards to detect the cases of the discriminant less than zero or equal to zero. The third case doesn't need a guard because it's the only remaining possibility. One other thing to note about this solution is that the first case has a single expression, but it's okay to have a block of statements inside of curly braces that yields a value for the switch…

Contents