Question #232381

String Slicing

Given two strings

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.


Expert's answer


function stringSlicing(){ 
   const string = prompt('Please input string');
   const sub = prompt('Please input sub string');
   const indexSub = string.indexOf(sub);
   if(indexSub !== -1){
      return string.slice(indexSub)
   } else {
      return string
   }
}
alert(stringSlicing());

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS