Code Lab

Yes or no

EasyFunctions3 min

Write a function ask(agree, yes, no). yes and no are functions too, they are callbacks.

If agree is true, call yes, otherwise call no. Return what the called function returned.

Examples

ask(true, () => 'ok', () => 'cancel')

Returns 'ok'

ask(false, () => 'ok', () => 'cancel')

Returns 'cancel'

Source

Loading the editor...
  1. With true returns the result of yes
  2. With false returns the result of no

Hidden tests run on Submit.