Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Discover a wealth of knowledge from professionals across various disciplines on our user-friendly Q&A platform. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.
Sagot :
Assuming you mean a function that truncates a string to 20 characters:
function fullwords(s){
if (s.length > 20) {
//find the 20th character
var char20 = s.charAt(19);
//if it's a space, return the string up to that point
if (char20 == " ") {
return s.substring(0, 20);
}
//if it's not a space, find the closest space
else {
var spaceBefore = s.lastIndexOf(" ", 18);
return s.substring(0, spaceBefore);
}
}
//if the string is shorter than 20 characters, return it unchanged
else {
return s;
}
}
To use fullwords(), simply pass in a string as the only argument. The function will then return a string that is no longer than 20 characters. If the string you passed in was shorter than 20 characters, it will be returned unchanged.
Learn more on string here:
https://brainly.com/question/28290531
#SPJ4
Thanks for stopping by. We are committed to providing the best answers for all your questions. See you again soon. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Keep exploring Westonci.ca for more insightful answers to your questions. We're here to help.