function generateRandomString(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var input = document.getElementById("length");
console.log(generateRandomString(input));
<html>
<body>
<div>
Enter the length of character:
<input type="text" id="length" />
<button onclick="generateRandomString(5)">Submit</button>
<p id="result"></p>
</div>
<script type="text/javascript" src="app/index.js"></script>
</body>
</html>
Please help me find the error. I cannot figure out why I'm not getting the output I expected. My goal is to display random text with a specific length based on the value entered in an HTML text field.