### Instruction:
Create a JavaScript application that uses the Web Audio API to generate different types of sound waves (sine, square, triangle, and sawtooth) at various frequencies and amplitudes.


### Response:

To create a JavaScript application that uses the Web Audio API to generate different types of sound waves, you can follow these steps:

1. Create an HTML file with a basic structure and include buttons for each type of wave and input fields for frequency and amplitude.

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web Audio API Sound Waves</title>
</head>
<body>
    <h1>Web Audio API Sound Waves</h1>
    <button id="sine">Sine Wave</button>
    <button id="square">Square Wave</button>
    <button id="triangle">Triangle Wave</button>
    <button id="sawtooth">Sawtooth Wave</button>
    <br><br>
    Frequency: <input type="number" id="frequency" value="440">
    Amplitude: <input type="range" id="amplitude" min="0" max="1" step="0.01" value="0.5">
    <script src="app.js"></script>
</body>
</html>
```

2. Create a JavaScript file (app.js) and start by initializing the Web Audio API context and creating an oscillator and gain nodes.

```javascript
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
let oscillator;
let gainNode;

function playSound(waveType, frequency, amplitude) {
  // Stop any existing oscillator
  if (oscillator) {
    oscillator.stop();
  }

  // Create a new oscillator node
  oscillator = audioContext.createOscillator();

  // Set the wave type, frequency, and amplitude
  oscillator.type = waveType;
  oscillator.frequency.value = frequency;

  // Create a gain node to control the amplitude
  gainNode = audioContext.createGain();
  gainNode.gain.value = amplitude;

  // Connect the oscillator to the gain node and the gain node to the output
  oscillator.connect(gainNode);
  gainNode.connect(audioContext.destination);

  // Start the oscillator
  oscillator.start();
}
```

3. Add event listeners for each button and input field, passing the appropriate wave type, frequency, and amplitude values.

```javascript
document.getElementById('sine').addEventListener('click', () => {
  const frequency = document.getElementById('frequency').value;
  const amplitude = document.getElementById('amplitude').value;
  playSound('sine', frequency, amplitude);
});

document.getElementById('square').addEventListener('click', () => {
  const frequency = document.getElementById('frequency').value;
  const amplitude = document.getElementById('amplitude').value;
  playSound('square', frequency, amplitude);
});

document.getElementById('triangle').addEventListener('click', () => {
  const frequency = document.getElementById('frequency').value;
  const amplitude = document.getElementById('amplitude').value;
  playSound('triangle', frequency, amplitude);
});

document.getElementById('sawtooth').addEventListener('click', () => {
  const frequency = document.getElementById('frequency').value;
  const amplitude = document.getElementById('amplitude').value;
  playSound('sawtooth', frequency, amplitude);
});

document.getElementById('frequency').addEventListener('input', (event) => {
  if (oscillator) {
    oscillator.frequency.value = event.target.value;
  }
});

document.getElementById('amplitude').addEventListener('input', (event) => {
  if (gainNode) {
    gainNode.gain.value = event.target.value;
  }
});
```

Now you have a simple JavaScript application that uses the Web Audio API to generate different types of sound waves at various frequencies and amplitudes. To test the application, open the HTML file in a web browser that supports the Web Audio API (such as Google Chrome or Mozilla Firefox).