Hi guys working on a problem in javascript from coder bytes. The problem is:
Using the JavaScript language, have the function ABCheck(str) take the str parameter being passed and return the string true if the characters a and b are separated by exactly 3 places anywhere in the string at least once (ie. "lane borrowed" would result in true because there is exactly three characters between a and b). Otherwise return the string false.
Use the Parameter Testing feature in the box below to test your code with different arguments.
function abcheck(str){
for(var i = 0; i < str.length; i++) {
if(str.split(" ")[i] === "a" && str.split(" ")[i+4] === "b")
{
return true;
}
else{
return false;
}
}
}
After doing a check
abcheck("Laura sobs")
I am getting false. Can anyone spot what I am doing wrong?