March 2019
Intermediate to advanced
208 pages
5h 11m
English
Create a variant data type called colorSpec that lets you specify a color in one of these ways:
| | let color1 = White; |
| | let color2 = Black; |
| | let color3 = Gray(0.50); /* Percentage gray as a float */ |
| | let color4 = RGB(255, 255, 255); /* Integers for Red, Green, and Blue */ |
Write a function that converts a colorSpec to a string in the form rgb(r,g,b). Here’s the starting point for your function:
| | let stringOfColorSpec = (cspec: colorSpec) : string => { |
| | /* your code here */ |
| | }; |
Here are examples of what it produces:
| | Js.log(stringOfColorSpec(White)); /* rgb(255,255,255) */ |
| | Js.log(stringOfColorSpec(Black)); /* rgb(0,0,0) */ |
| | Js.log(stringOfColorSpec(Gray(0.5))); ... |
Read now
Unlock full access