JSFiddle - React, Tailwind, and code Playground

HTML

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.

JavaScript

function ABCheck(str){
    for(i = 0; i < str.length;i++){
        if(str[i] === "b" && (str[i-4] ==="a" || str[i + 4] ==="a")){
            return true;
        }
    }
    return false;
}
console.log(ABCheck("after badly")); // false
console.log(ABCheck("after it")); // false
console.log(ABCheck("aaaaddddd")); // false
console.log(ABCheck("Laura sobs")); // true
console.log(ABCheck("abccccazzzb")); //true
console.log(ABCheck("bzzza")); // true