Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

use indexof() and substr() or substring() to display the end of the sen…

Question

use indexof() and substr() or substring() to display the end of the sentence starting from the wordsqueaky.
note: your code will be tested with more values for oldsaying.
1 let oldsaying = \the squeaky wheel gets the grease.\;
2
3 / your solution goes here /
4

Explanation:

Step1: Find the index of "squeaky"

Use indexOf() method to find the starting index of the word "squeaky" in the oldSaying string.

let index = oldSaying.indexOf("squeaky");

Step2: Extract the substring

Use substr() (or substring()) method to extract the substring starting from the found index.

let result = oldSaying.substr(index);
// or let result = oldSaying.substring(index);
console.log(result);

Answer:

let oldSaying = "The squeaky wheel gets the grease.";
let index = oldSaying.indexOf("squeaky");
let result = oldSaying.substr(index);
// or let result = oldSaying.substring(index);
console.log(result);