nearBy AZ


Anyone can help me with this problem? It should work, but id does not

// Write a method that takes a string in and returns true if the letter
//# "z" appears within three letters **after** an "a". You may assume
//# that the string contains only lowercase letters.
function nearBy_az(string) {
    var indA
    var indZ
    len = string.length
    for(i=0; i<=len; i++){ 
        indA == i
    for(j=i+1; j<=len; j++) {
        indZ == j
    if(string [indA] =="a" && string[indZ] == "z" && indA+indZ<=3) {
        return true
    return false




Link to the lesson please.


Yeah please sent me a screenshot I will love to help with your code.


Hi, it is not from a codeacademy. I thought it is possible to do it with for loop. Problem description you can see on the top of the code.
Thank you


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.