+ 1
why does it stop after finding the first letter
function ind(word,letter){ for(var i=0;i<word.length;i++){ if(word.slice(i,i+1)==letter){ return "the index is "+i } } } alert(ind("banana","a")) i want to ask why doesnt the loop continue till the end
2 Respuestas
+ 6
The return statement immediately stops executing the function and returns control back to the caller. That is its purpose.
+ 1
Ohhk thanks Brian