---
id: 587d7dbc367417b2b2512bae
title: Build a Drum Machine
isRequired: true
challengeType: 3
videoUrl: ''
localeTitle: 建立鼓机
---

## Description
<section id="description"> <strong>目标：</strong>构建一个功能类似于此的<a href="https://codepen.io" target="_blank">CodePen.io</a>应用程序： <a href="https://codepen.io/freeCodeCamp/full/MJyNMd" target="_blank">https</a> <strong>：</strong> <a href="https://codepen.io" target="_blank">//codepen.io/freeCodeCamp/full/MJyNMd</a> 。完成以下<a href="https://en.wikipedia.org/wiki/User_story" target="_blank">用户故事</a>并通过所有测试。给它你自己的个人风格。您可以使用HTML，JavaScript，CSS，Bootstrap，SASS，React，Redux和jQuery的任意组合来完成此项目。您应该使用前端框架（例如React），因为本节是关于学习前端框架的。不建议使用上面未列出的其他技术，使用它们的风险由您自行承担。我们正在寻求支持其他前端框架，如Angular和Vue，但目前不支持它们。我们将接受并尝试修复所有使用建议的技术堆栈的问题报告。快乐的编码！ <strong>用户故事＃1：</strong>我应该能够看到一个带有相应<code>id=&quot;drum-machine&quot;</code>的外部容器，其中包含所有其他元素。 <strong>用户故事＃2：</strong>在<code>#drum-machine</code>我可以看到一个具有相应<code>id=&quot;display&quot;</code>的元素。 <strong>用户故事＃3：</strong>在<code>#drum-machine</code>我可以看到9个可点击的鼓垫元素，每个鼓垫元素都有一个<code>drum-pad</code>的类名，一个唯一的id描述了鼓垫将被设置为触发的音频片段，以及一个内部与键盘上的以下键之一对应的文本：Q，W，E，A，S，D，Z，X，C。鼓垫必须按此顺序排列。 <strong>用户故事＃4：</strong>在每个<code>.drum-pad</code> ，应该有一个HTML5 <code>audio</code>其具有元件<code>src</code>指向音频剪辑，一个类名称属性<code>clip</code> ，以及对应于其父的内文本的ID <code>.drum-pad</code> （例如<code>id=&quot;Q&quot;</code> ， <code>id=&quot;W&quot;</code> ， <code>id=&quot;E&quot;</code>等）。 <strong>用户故事＃5：</strong>当我点击<code>.drum-pad</code>元素时，应该触发其子<code>audio</code>元素中包含的音频剪辑。 <strong>用户故事＃6：</strong>当我按下与每个<code>.drum-pad</code>相关联的触发键时，应触发其子<code>audio</code>元素中包含的音频剪辑（例如，按下Q键应触发包含字符串“Q”的鼓垫，按下W键应触发包含字符串“W”等的鼓垫。 <strong>用户故事＃7：</strong>当触发<code>.drum-pad</code> ，描述相关音频剪辑的字符串将显示为<code>#display</code>元素的内部文本（每个字符串必须是唯一的）。您可以通过分叉<a href="http://codepen.io/freeCodeCamp/pen/MJjpwO" target="_blank">此CodePen笔</a>来构建项目。或者您可以使用此CDN链接在您喜欢的任何环境中运行测试： <code>https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js</code> ： <code>https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js</code>完成后，将URL提交给您的工作通过所有测试的项目。如果卡住，请记住使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514" target="_blank">Read-Search-Ask</a>方法。 </section>

## Instructions
<section id="instructions">
</section>

## Tests
<section id='tests'>

```yml
tests: []

```

</section>

## Challenge Seed
<section id='challengeSeed'>

</section>

## Solution
<section id='solution'>

```js
// solution required
```
</section>
