Question

In: Computer Science

Create a JavaScript program that asks for the input of at least five words (a total...

Create a JavaScript program that asks for the input of at least five words (a total of 25+ characters) string from a user and performs the following functions to it:

STRING METHODS

  1. Check to see if the string input meets the 25+ character limit. If it does not, send a message and ask for another string.
  2. Output the original string as it was entered onto the web page document.
  3. Output the original string in all lower case letters. Do not change the original string value.
  4. Output the original string in all upper case letters. Do not change the original string value.
  5. Output a message indicating the total characters within the string.
  6. Output the characters between index 5 and index 10.
  7. Output 5 characters starting from position 15.
  8. Combine the string with another string of your choice that also has 25+ characters. The new string should be at the end of the first string. Output the combined string.
  9. Finally, split your string into an array for the 2nd part of the assignment. Each word (not each character) should be a value for the array.

Example: Input 5 words

Note: This is an example with example input. Your input will make this much different so don't hard code my examples into your code. The program should ask for input for the 5 words.

Enters: I think therefore I am

Check to make sure it is 25 characters in length. (step 1) - it is not, it is only 22 characters so have them try again.

Enters: Failure is success in progress (this is over 25 characters)

Output: Failure is success in progress (step 2)

Output in lowercase: failure is success in progress (step 3)

Output in uppercase: FAILURE IS SUCCESS IN PROGRESS (step 4)

Output character count: Your string has 30 characters. (step 5)

Output characters between index 5 and 10. re is (step 6)

Output 5 characters starting from position 15. ess i (step 7)

Combine with a 25+ character string you have created: Failure is success in progress Success is dependent on effort (step 8)

ARRAY METHODS - Working with the same string as the String Methods program, continue your program by completing these steps.

  1. Output the list of array values.
  2. Output the total number of items in the array.
  3. Remove the first item in the array. Output the new array values.
  4. Add the word "banana" to the end of the array. Output the new array values.
  5. Reverse the elements in the array. Output the new array values.
  6. Replace the item in the 2nd position/key with the word stardust. Output the new array values showing the word in the correct position.
  7. Sort the array in alphabetical order. Output the alphabetical list of array values.

Example continued: Array Methods

Your list should be output of all words in your combined string: (step 1)

failure
is
success
in
progress
Success
is
dependent
on
effort

Output: Your string contains 10 words. (step 2)

Output after removing the first array item (step 3)

is
success
in
progress
Success
is
dependent
on
effort

Output after adding the word banana to the end of the array (step 4)

is
success
progress
Success
is
dependent
on
effort
banana

Output after reversing the array elements (step 5)

banana
effort
on
dependent
is
Success
progress
success
is

Output after updating the second array item with the word stardust (step 6)

banana
effort
stardust
dependent
is
Success
progress
success
is

Output after sorting the array (step 7)

Success
banana
dependent
effort
is
is
progress
stardust
success

Solutions

Expert Solution

<input id="enter"></input>

<button id="check" onclick="myFunc(this);">Enter</button>

<div id="showcheck"></div>

<script type="text/javascript">

let text = document.getElementById("enter");

let btn = document.getElementById("check");

let output = document.getElementById("showcheck");

//declaring a function to wrap steps to be performed

let myFunc = function (e){

  //reset the outout div

  output.innerText = "";

  //get the text

  let str = text.value;

  //check if length matches requirement

    if(text.value.length <= 25){

      //show retry message

      alert("String length is less than 25 characters. PLease try again!");

      //reset the textbox

      text.value = "";

    }

    else{

      //get the value

      str = text.value;

      //show it

      output.innerText += "\nOutput: "+str+"\n";

      //lowercase

      output.innerText += "\nOutput in lowercase: " + str.toLowerCase()+"\n";

      //uppercase

      output.innerText += "\nOutput in uppercase: " + str.toUpperCase()+"\n";

      //character count

      output.innerText += `\nOutput character count: Your string has ${str.length} characters.\n`;

      //character bwetween 5 and 10

      output.innerText += `\ncharacters between index 5 and 10. ${str.slice(5,10)}\n`;

      // 5 charcaters after index 15

      output.innerText += `\nOutput 5 characters starting from position 15. ${str.slice(15, 20)}\n`;

      //create your own string

      let created_str = "Success is dependent on effort.";

      //concat the strings

      str = str +" "+ created_str;

      output.innerText += `\nCombine with a 25+ character string you have created: ${str}\n`;

      //convert words to a array

      let arr = str.split(" ");

      output.innerText += `\nArray: \n`;

      for (let i of arr){

        output.innerText += `${i}\n`;

      }

      //output total number of elements

      output.innerText += `\nYour string contains ${arr.length} words.\n`;

      //remove 1st element

      arr.shift();

      //display

      output.innerText += `\nAfter removing 1st item,\n`;

        for (let i of arr) {

        output.innerText += `${i}\n`;

      }

      //add banana

      arr.push("banana");

      //display

      output.innerText += `\nAfter adding banana to the last,\n`;

      for (let i of arr) {

        output.innerText += `${i}\n`;

      }

      //reverse the array

      arr = arr.reverse();

      //display

      output.innerText += `\nAfter reversing array,\n`;

      for (let i of arr) {

        output.innerText += `${i}\n`;

      }   

      // after updating the second array item with the word stardust

      arr[2] = "stardust";

      //display

      output.innerText += `\nafter updating the second array item with the word stardust,\n`;

      for (let i of arr) {

        output.innerText += `${i}\n`;

      }   

      console.log(arr);

      

      //after sorting the array

      arr.sort();

      //display

      output.innerText += `\nafter sorting,\n`;

      for (let i of arr) {

        output.innerText += `${i}\n`;

      }

      //clear the text field

      text.value = "";

    }

  }

</script>


Related Solutions

Create the logic for a rhyming program that takes in five words from a user input...
Create the logic for a rhyming program that takes in five words from a user input and replaces the selected rhyming words with the user's input, then creates and displays the Humpty Dumpty rhyme with the five words from the user input. Hint: 1. You will use the sentinel values: start and stop 2. The program will ask the user for 5 words. 3. The program will store the 5 words 4. The program outputs the rhyme replacing the ____...
Q1 Create a program that asks the user to input their budget. Then, it will ask...
Q1 Create a program that asks the user to input their budget. Then, it will ask the user to input each of their purchase until their entire budget is used up. What kind of loop do you think is the most appropriate? You don't have to create the entire program. Part of it has already been created for you (see code below). Note: Assume that the user always uses up their budget to the last cent and they don't over...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
Write a javascript program that computes the total cost for a five year car lease. The...
Write a javascript program that computes the total cost for a five year car lease. The program starts with a monthly leasing amount and a yearly increase in percent. The program then outputs the total amount paid for each year and the total overall cost of the lease.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write in javaScript: User input 5 words in one input, and print out the longest word.
Write in javaScript: User input 5 words in one input, and print out the longest word.
In Java:Implement a program that repeatedly asks the user to input apositive integer and...
In Java:Implement a program that repeatedly asks the user to input a positive integer and outputs the factorial of that input integer. Do not use recursion, solution should use stack.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT