converted example to JavaScript