JavaScript code below: