1. Put the following variable with your other variables

var audioCtx = new(window.AudioContext || window.webkitAudioContext || window.audioContext);

2. Put the following function with your other functions

//All arguments are optional:
//duration of the tone in milliseconds. Default is 500
//frequency of the tone in hertz. default is 440
//volume of the tone. Default is 1, off is 0.
//type of tone. Possible values are sine, square, sawtooth, triangle, and custom. Default is sine.
//callback to use on end of tone
function beep(duration, frequency, volume, type, callback) {
    var oscillator = audioCtx.createOscillator();
    var gainNode = audioCtx.createGain();

    oscillator.connect(gainNode);
    gainNode.connect(audioCtx.destination);

    if (volume) { gainNode.gain.value = volume; }
    if (frequency) { oscillator.frequency.setValueAtTime(frequency, audioCtx.currentTime); }
    if (type) { oscillator.type = type; }
    if (callback) { oscillator.onended = callback; }

    oscillator.start();
    setTimeout(function() { oscillator.stop() }, (duration ? duration : 500));
}

This function was copied from here.

3. Call the beep function where you want to play a sound

beep(someMilliseconds, someFrequency);
Note Frequency (in hertz)
C 262
D 294
E 330
F 349
G 392
A 440
B 494
Complete list of frequencies