<button id="play">Beep</button>
(function() {
  'use strict';

  const playButton = document.querySelector('#play');
  const context = new AudioContext();

  playButton.onclick = oscillate;

  function oscillate() {
    const oscillatorNode = context.createOscillator();

    oscillatorNode.type = 'triangle';
    oscillatorNode.frequency.value = 150;
    oscillatorNode.connect(context.destination);
    oscillatorNode.start();
    oscillatorNode.stop(context.currentTime + 1);
  }
}());
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.