Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

find the index of the string near and assign substringindex with the in…

Question

find the index of the string near and assign substringindex with the index. then, update wiseproverb replacing near with close.
note: your code will be tested with more values for wiseproverb.
1 let wiseproverb = \keep your friends near and your enemies closer.\;
2 let substringindex = 0;
3
4 / your solution goes here /
5

Explanation:

Step1: Find the index of "near"

Use the indexOf method. substringIndex = wiseProverb.indexOf("near");

Step2: Replace "near" with "close"

Use the replace method. wiseProverb = wiseProverb.replace("near", "close");

Answer:

let wiseProverb = "Keep your friends near and your enemies closer.";
let substringIndex = 0;
substringIndex = wiseProverb.indexOf("near");
wiseProverb = wiseProverb.replace("near", "close");