Question: In Javascript add a user input that asks the user to enter the number of job duties that they want to see that you preformed
In Javascript add a user input that asks the user to enter the number of job duties that they want to see that you preformed at your previous job. When the user clicks a button, a function will be called and will then take this input and use it to specify an index number of an array that will be the starting point of the array values (duties) to be displayed. Through looping, we will then subtract 1 from the index number until it reaches 0 and display all of the values that are associated with the index numbers that were calculated during the loop. We will be making two of these functions (one for each job), but will be copying a great deal of the code from one over to the other.
a. Create an input that acts as a fill in the blank for a sentence that prompts the user to enter the number of job duties they want to see.
b. Create a button that calls a function when clicked (the function created in the next step) c. Crate a function that takes the user input and assigns the value to a variable. i. Explanation of why we did step 1
c: This variable represents the number of job duties the user wants listed d. Create an array with at least five job duties in it. i. Explanation of step 1 d: Remember that the index starts at 0 and not 1. ii. In the next steps we print out the array values by referencing their associated index numbers, starting at the highest index number that we want printed and counting down. The highest index number that we want printed is the number that the user wants to be displayed minus 1. 1. Explanation of why we did step 1 d ii: If we did not obtain the highest index number that we want to print by subtracting 1 from the number that the user wants to be displayed and instead just used the user input as the highest index number we would actually print out the number the user wants to be displayed plus an extra. For example, if the user asks for 3, we would count down index values: 3,2,1,0. Since that is INF 201 Assignment 5 actually 4 values we will need to adjust for this in the next step by removing the first value before the loop starts. e. Create a new variable and set it equal to the inputted value minus 1 i. Explanation of why we did step 1
e: This variable is essentially representing the first index number that we will call to be printed out, as discussed above.
f. Create a while loop that runs while the variable (that represents the index value that we want to print) is greater than or equal to the minimum array value.
g. Within the while loop have two things happen. i. Have the innerHTML of some element within your page be replaced with the array value that corresponds to the index number that we want printed 1. You specify the array value by the format arrayname[indexnumber] ii. Have the index subtract one from itself to count down
h. At this point your function should run, but it does not work properly. Only the array value at the last index is printed. To fix this, we need to concatenate the results of the loop. i. Create a new variable outside of the loop and set it to be equal to blank 1. You do this by setting it equal to ii. Within the loop, make this variable to be equal to itself plus the array value that we want printed. iii. Now change the innerHTML to be equal to this variable
Question: What happens if we do not set this variable equal to blank first?
i. Copy this function over and change the name of the function, the id of the output and input, and the array values to make it work for your second job.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
