Question

Write a java script function that accepts a string as input and prints the 3rd, 5thand...

Write a java script function that accepts a string as input and prints the 3rd, 5thand 7thwordof input string with ‘-‘ in between the words. Spaces at the start and end of string must be

ignored.

it done html and javascript and plz do it in simple way

Homework Answers

Answer #1

javascript and html code:

<html>
   <head>

      <script type = "text/javascript">
         function printFunction(words)
         { //main function

            words=words.trim(); //trim the string to ignore space at begin & end.
            var wordArray = words.split(" "); //split the string by space and make array.
          
            //print the values as per requirement.
            document.write(wordArray[3]+"-"+wordArray[5]+"-"+wordArray[7]);
          
         }
       
         function callFunc(){ //driver function
          var str="Artificial Intelligence looks all set to be the future of the World"; //string to be passed.
          printFunction(str); //call the function to print the values
         }
      </script>
    
   </head>
   <body>
      <p>Click the following button to call the function</p>
    
      <form>
         <input type = "button" onclick = "callFunc()" value = "Call Function">
      </form>
    
      <p>Use different text in write method and then try...</p>
   </body>
</html>

Output:

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
Write a java script function that accepts integer array, searchKey as input, display True if the...
Write a java script function that accepts integer array, searchKey as input, display True if the value is found in the array, else display False. it done html and javascript and plz do it in simple way
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Given a string . Find the numberical sum of the string . Example 1: Given String...
Given a string . Find the numberical sum of the string . Example 1: Given String = "abcd" Numerical Sum = 1 + 2 + 3 + 4 = 10, Since a = 1 , b = 2 , c =3 and d = 4 it done html and javascript and plz do it in simple way
Write a function that takes as input an English sentence (a string) and prints the total...
Write a function that takes as input an English sentence (a string) and prints the total number of vowels and the total number of consonants in the sentence. The function returns nothing. Note that the sentence could have special characters such as dots, dashes, and so on. write a python program please.
Write a method that accepts a String object as an argument and displays its contents backward....
Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argument is "gravity" the method should display "ytivarg". Demonstrate the method in a program that asks the user to input a string and then prints out the result of passing the string into the method. Sample Run java BackwardString Enter·a·string:Hello·world↵ dlrow·olleH↵
Write a program that takes a string of words, and prints out these words one per...
Write a program that takes a string of words, and prints out these words one per line in a rectangular format (using # shape). The output must be properly formatted. (Save your script as tabularFormat.py and tabularFormat.txt) If the input is: “Roses are red, sky is blue, I mind my own business, why can’t you!”The output would be: (With Comments )
1. Write a script in Bourne Shell that prints out the following table. Use a while...
1. Write a script in Bourne Shell that prints out the following table. Use a while loop to do so. \t can be used with echo to create a tab space. N S 1 1 2 4 3 9 2. Write a Bourne Shell script that uses a function that you write called cube (you need to write the body of the function in the script) that accepts a variable whose value is cubed and prints our this cubed value....
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. -->...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
Finally, write a script named word_counts.sh that prints out how many words are on each line...
Finally, write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT