Exercise 2: Injecting Multiple Properties
Solve another exercise to polish your skills of metaprogramming.
We'll cover the following
Problem statement
In the following code, create custom properties to extract the integer part and the fractional part from a number.
Add two properties to the instances of Number
for the integer and fractional parts separately.
Sample input and output
The input calls and their respective outputs are given below for your help.
Input | Output |
---|---|
printParts(22.12); |
whole: 22 decimal: 12 |
printParts(.14); |
whole: 0 decimal: 14 |
printParts(-23.19); |
whole: -23 decimal: 19 |
printParts(42); |
whole: 42 decimal: 0 |
Exercise
Let’s solve this mystery.
Solve this challenge and test your skills of metaprogramming the first flavor–member injection.
Get hands-on with 1400+ tech skills courses.