Exercise 2: Proxy
Test your skills of proxy by solving this exercise.
We'll cover the following
Problem statement
Create a proxy that will receive a method that starts with play
and returns the string message “I love to play …” message if the part after play
is contained in an activities array field.
For example, when playTennis()
is called, the message will be “I love to play Tennis”. If the activity is not contained in the array, the “I don’t play …” message is returned. For any call that does not start with play
, an exception should be thrown.
Sample input and output
The sample input calls and their respective outputs are given in the table below.
Input | Output |
---|---|
console.log(proxy.playTennis()); |
I love to play Tennis |
console.log(proxy.playFootball()); |
I love to play Football |
console.log(proxy.playPolitics()); |
I don’t play Politics |
console.log(proxy.dance()); |
dance is not a function |
Exercise
Good luck solving the above challenge!
Get hands-on with 1400+ tech skills courses.