Question

Need HTML and JS code. Write a Javascript function named RandomString(randomStringLength) that returns a string filled...

Need HTML and JS code.

Write a Javascript function named RandomString(randomStringLength) that returns a string filled with random characters where the length of the random string is defined by the input parameter.

HINT: Use a for-loop, Math.random, and the fact that the alphabet has 26 characters (remembering that we can have both lower-case and upper-case characters in a string).

This is what I have:

<html>
<!-- inputbox.html Jerry Davis -->
<!-- Web page that sets the correct letter value. -->
<!-- ========================================== -->
<head>
<script>function RandomString(randomStringLength){

var text = "";

var char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for(var i=0; i < randomStringLength ; i++ )

text += char_list.charAt(Math.floor(Math.random() * char_list.length));

return text;

}
</script>
</head>

<body>


<input id="random"/>

<button onclick="myFunction()">random output</button>

<p id="demo"></p>

</body>
</html

------

What am I doing wrong

Homework Answers

Answer #1

I have corrected your code. Bold part are the changes. You didnt implemented the myFunction method which is called on click of button: -

<html>
<!-- inputbox.html Jerry Davis -->
<!-- Web page that sets the correct letter value. -->
<!-- ========================================== -->
<head>
<script>
function RandomString(randomStringLength){

var text = "";

var char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for(var i=0; i < randomStringLength ; i++ )

text += char_list.charAt(Math.floor(Math.random() * char_list.length));

return text;

}

function myFunction() {
   var num = document.getElementById("random").value;
   var output = "";
   if(num == null || num == '') {
       output = "Please enter a length in the input box and Click on random output button again.";
   } else {
       output = RandomString(num);
   }
   document.getElementById("demo").innerHTML=output;
}

</script>
</head>

<body>


<input id="random"/>

<button onclick="myFunction()">random output</button>

<p id="demo"></p>

</body>
</html>

Output Samples: -

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
HTML and Java script Is there a way to delete an element of an array? For...
HTML and Java script Is there a way to delete an element of an array? For example when I click this first button then a random word will appear then when I click this second button then the randomized word will be deleted or removed from the array. here is the portion of the code <button class="wew" onclick="thesisFinal()"><i class="fa fa-play-circle"> Start</i></button></div>              <button class="wew" onclick="removeThesis()"><i class="fa fa-play-circle"> Start</i></button></div>              <p id="thesisget">Click to generate</p>           ...
Please linked both files. For this assignment you need to create a ToDo list using Javascript,...
Please linked both files. For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link...
<!doctype html> <html lang=”en”>   <head>     <title>Principal Calculation Form</title>     <meta charset="utf-8"/>         
<!doctype html> <html lang=”en”>   <head>     <title>Principal Calculation Form</title>     <meta charset="utf-8"/>                   <script src="code.js"></script>   </head>      <body onload="setFocus();">     <div class="container">                                       <div class="main">                                                                                <form action="#" method="post" name="form_name" id="form_id" class="form_class" >                                                                           <h2>--Principal Loan Form--</h2>                                                                                                                                                      <h5>Disclaimer: This software by no mean will precisely predict your mortgage through your lender company.  This Software will only assume the four items below in order to make an educated guess or prediction to your exact mortgage interests amount and the duration of your loan from your lender. <img...
Hello, I am trying to create a java script code that can arranges the input lowest,...
Hello, I am trying to create a java script code that can arranges the input lowest, highest, finding average, sort them and the clear form functionality. I managed to create the code that sorts the number input from lowest to highest but I am stuck on the rest. See the code below Please help. <!DOCTYPE> <html> <head> <title>EXAM01_01</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#ans4,#numbers{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> <script>    function readNumbers()...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
How to write a Javascript application using code below that reads names separated by spaces and...
How to write a Javascript application using code below that reads names separated by spaces and for output lists the names with the first letter of every name converted to uppercase and the rest to lower case making sure to sort the output list. <!DOCTYPE> <html> <head> <title>EXAM01_02</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#names{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> </head> <body>    <form>    <div class="title"><label>EXAM01_02</label></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>Enter...
The following code shows the head and body sections in an HTML file: <head> <script> function...
The following code shows the head and body sections in an HTML file: <head> <script> function init() { var x, y, z; z = document.getElementById("abc").innerHTML; y = "B"; x = "C"; document.getElementById("abc").innerHTML = x+y+z; } </script> </head> <body onload="init();"> <p id="abc">A</p> </body> What would be displayed on the browser when the above webpage is opened? BC CB or CBA or A or ABC
*To the guy who answered last time. You're not following the directions. Please follow specific directions...
*To the guy who answered last time. You're not following the directions. Please follow specific directions below.* Create a "web page" with the following components: An input field for the "number of rounds to play" The "number of remaining" rounds should also be displayed somewhere on the screen. A button to "Start" the game play. The function attached to this button can "setup" the rest of the game. For example: initialize counters, show/hide other components, etc. A set of buttons...
Using Notepad++, copy the code presented in Listing 26.2, "A Form That Displays Data in a...
Using Notepad++, copy the code presented in Listing 26.2, "A Form That Displays Data in a Pop-Up Window," in the subsection "Displaying Data From a Form" in the section "Accessing Form Elements With JavaScript" in Ch. 26, "Working with Web-Based Forms of Sams Teach Yourself HTML, CSS and JavaScript All In One. Save the file using the name Week4ValidationExample.html. Test your code and debug as necessary. Change the name of the display() function to myDisplay() where my is your first...
Part 1: Create the grid tic-tac-toe gameboard using buttons and iteration. Part 2: Human user gets...
Part 1: Create the grid tic-tac-toe gameboard using buttons and iteration. Part 2: Human user gets to select an open cell on the grid - place an X on that button selected Part 3: Check for a win using DOM iteration - new game option if row or column matching X pattern Part 4: Computer gets to select an open cell on the grid - place an O on that button selected Part 5: Check for a win using DOM...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT