Ii CHT
Ii CHT
---
4. **Explain DOM**:
- The DOM (Document Object Model) is a programming interface for web
documents. It represents the structure of an HTML or XML document as a tree of
objects, where each element is a node. JavaScript can manipulate the DOM to
dynamically change the content, structure, and styling of a webpage.
5. **Write a JavaScript program to create four buttons on the web page. Clicking
on a button will change the background color of the web page**:
```javascript
<!DOCTYPE html>
<html>
<body>
<button onclick="changeColor('red')">Red</button>
<button onclick="changeColor('green')">Green</button>
<button onclick="changeColor('blue')">Blue</button>
<button onclick="changeColor('yellow')">Yellow</button>
<script>
function changeColor(color) {
document.body.style.backgroundColor = color;
}
</script>
</body>
</html>
```
---
<label for="address">Address:</label>
<input type="text" id="address" name="address"><br><br>
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
```
// Example usage
let number = 28;
console.log(isPerfectNumber(number) ? `${number} is a perfect number` : `$
{number} is not a perfect number`);
```
---