<html>
<head>
<style>
.output {
width: 90%;
height: 50vh;
overflow-y: auto;
}
button {
margin: .25rem;
cursor: pointer;
}
</style>
</head>
<body>
<div class="output"></div>
<script>
function doit(name) {
const output = document.querySelector('.output');
output.innerHTML += `<div>You clicked: ${name}</div>`;
output.scrollTop = output.scrollHeight; // Auto scroll down
}
const items = ['CAT', 'DOG', 'HAMSTER', 'PARROT', 'FISH', 'GUINEA PIG'];
for (const item of items) {
document.body.innerHTML += `<button onclick="doit('${item}')">PET ${item}</button>`;
}
</script>
</body>
</html>