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
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:
Get Answers For Free
Most questions answered within 1 hours.