Question: I'm trying to add the required attribute to a radio input with javascript. I currently have `document.getElementsByClassName("LMB")[0].required = true;`, which gives me the error document.getElementsByClassName(...)[0] is undefined.

Here is the html code I'm using.

```
<input type="radio" name="LMB" id="yes" value="Yes">
<label for="yes">Yes</label>
<input type="radio" name="LMB" id="no" value="No">
<label for="no">No</label>

```

Answer: 
Your inputs don't have `class="LMB"`, add it and try again:

```js
document.getElementsByClassName("LMB")[0].required = true;
```

```html
<input class="LMB" type="radio" name="LMB" id="yes" value="Yes">
<label for="yes">Yes</label>
<input class="LMB" type="radio" name="LMB" id="no" value="No">
<label for="yes">No</label>
```

However, if you want to use the name attribute, you could use `document.getElementsByName`:

```js
document.getElementsByName("LMB")[0].required = true;
```

```html
<input type="radio" name="LMB" id="yes" value="Yes">
<label for="yes">Yes</label>
<input type="radio" name="LMB" id="no" value="No">
<label for="yes">No</label>
```
The correct method to use when targeting the `name` attribute of the `input` elements is 

```
document.getElementsByName

```

See <https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName>

```js
document.getElementsByName("LMB")[0].required = true;
```

```html
<input type="radio" name="LMB" id="yes" value="Yes">
<label for="yes">Yes</label>
<input type="radio" name="LMB" id="no" value="No">
<label for="no">No</label>
```

---

Also your second label should use `for="no"`