March 2019
Intermediate to advanced
208 pages
5h 11m
English
The last data type we’ll take up in this introduction is strings. Multi-character strings are enclosed in double quotes, and the ++ operator concatenates strings. Consider this statement:
| | let str = "door" ++ "bell"; /* binds value "doorbell" to variable str */ |
Back in the discussion of output for the program, we noted that code such as the example below doesn’t compile properly because ++ requires both its operands to be strings. The variable total is float, and the compiler will complain bitterly:
| | let total = float_of_int(qty) *. price; |
| | |
| | let afterDiscount = total *. (1.0 -. discount); |
| | |
| | Js.log("Price before discount: $" ++ total ++ "."); |
| | Js.log("Price after discount: $" ... |
Read now
Unlock full access