Course of Raku / Advanced / Containers / Scalar containers / Exercises

Default discount

Problem

Declare a scalar variable $discount so that it has a default value of 0. Print the variable before assigning anything to it — the program must print 0 without producing any warning.

Then assign 15 to the variable and print it again.

Example

The program prints two lines:

0
15

Solution

See the solution

Course navigation

Proxying method calls   |   Solution: Default discount