I would like to be able to generate 1 or a list of 10. It works, but I would like to have the option generate more than 1 at a time. The string must begin with 0x and have 16 characters after the 0x.
Here is a Fiddle
Please include the full code with output results instead of just the results in console.log
I added a second button to generate 10 and called it btn10. Then I tried tweaking the code to give different things a unique id, but must admit, I am completely lost.
const button = document.querySelector('#btn');
const hexValues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
const value = document.querySelector('.hexValue');
button.addEventListener('click', changeHex);
function changeHex() {
let hex = '0x';
for (let i = 0; i < 16; i++) {
const index = Math.floor(Math.random() * hexValues.length)
hex += hexValues[index];
}
value.textContent = hex;
}
<div class="container">
<h1><span class="hexValue">Generate</span></h1>
<button id="btn">Generate 1</button>
<button id="btn5">Generate 5</button>
</div>
2
Answers
Here is a version using delegation, map and template literals
Study it and see if you can learn from it
or