getRandomInt() function: generate a random integer startup() function: entry point function call to startup() function

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Part 3: JavaScript - Program Outline, Startup Function, and Prompt

We are going to use a function that we can consider an entry point into our running JavaScript. Below is an outline of the major elements in our JavaScript file.

  • getRandomInt() function: generate a random integer
  • startup() function: entry point function
  • call to startup() function

Below is your startup code:

function getRandomInt(min, max) {}

function startup() {}

startup();

>> Add the above code components to your cis111-07.js JavaScript file below your multiline comment.

>> Copy the getRandomInt function code from your previous assignment, or from this Stackoverflow article (Links to an external site.). Remember to add a single line comment above the getRandomInt function that documents the source of the code.

Before attempting to use the prompt function in your code, you should try out the function in the console.

>> Enter the following into the console to test displaying the prompt dialog.

prompt();

Prompt can include an optional text prompt.

>> Enter the following into the console to display a text prompt in the prompt dialog.

prompt("Enter data:");

The prompt function will return whatever was typed into the prompt dialog.

>> Enter the following into the console to store and display the user-input into the prompt dialog.

let input = prompt("Enter data:");

Now that you're familiar with how prompt works, let's add prompt to our startup function.

>>  Add the prompt function to the startup function, using appropriate prompt text. Capture the input returned from the prompt function into a variable.

Part 4: JavaScript - Prompt Loop and Storing Input

The next element of the program is to continue to prompt the user for input, storing each input into an array, until the user does not enter anything into the prompt dialog. First, you'll need an empty array.

>> Add an empty array to the startup function. Name the array data. Declare the array as a constant array.

Tip: Making our array a constant array prevents us from accidentally overwriting the entire array contents, but does not prevent us from adding data to the array.

With the input storage ready, we can know work on our prompt loop. You will need to figure out how to continuously prompt the user for input using the prompt function, and either a while loop, or a do...while loop - either loop structure will work. You can ignore storing the input for now, and just focus on the prompt loop.

>> Add code to the startup function to continuously prompt the user for input using either while or do...while, and the prompt function, until the user leaves the prompt input dialog empty. 

Tip: You will need to use String functionality to test if the input is empty or not.

Once you have the prompt loop complete, you can modify the loop to capture the input by adding each input into the data array.

>> Add code to the prompt loop that adds the input into the array. You will need to use an array function that adds array elements to the end of the array. After each input is added to the array, the array will be one element in length larger.

Tip: The assignment will require all input to be converted to upper case letters, and to be displayed in a random color. You may be tempted to modify the input data as the data is added to the array, but leave the data as entered by the user.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY