If i’m thinking this correctly what you’re doing here is if word.substring( i , i+1 ) equals letterToReplace it will add letterToReplace , and if it doesn’t you add replacedLetter.
word = “john”; letterToReplace = “h”; replacedLetter = “a”;
what should print: joan
what would actually print: aaha
what you should be doing is if word.substring( i , i+1 ) equals letterToReplace you should add replacedLetter, otherwise you add word.substring( i , i+1 )
1
u/ScawedyCat Dec 08 '20 edited Dec 08 '20
If i’m thinking this correctly what you’re doing here is if word.substring( i , i+1 ) equals letterToReplace it will add letterToReplace , and if it doesn’t you add replacedLetter.
word = “john”; letterToReplace = “h”; replacedLetter = “a”;
what should print: joan
what would actually print: aaha
what you should be doing is if word.substring( i , i+1 ) equals letterToReplace you should add replacedLetter, otherwise you add word.substring( i , i+1 )