george Posted November 18, 2015 Share Posted November 18, 2015 Within script tags in the body of my HTML, I have: aRay = new Array(); aRay[0] = 'a'; aRay[1] = 'b'; aRay[2] = 'c'; aRay[3] = 'd'; aRay[4] = 'e'; document.write("aRay length is "+aRay.length+"</br>"); for( i = 0; i < aRay.length; i++ ) document.write("element "+i+" is "+aRay[i]+"</br>"); for( y = 0; y < aRay.length; y++ ) { if(aRay[y]='d') document.write("so we can find ""+aRay[y]+"" in element "+y+"</br>"); break; endif; } And what prints out is: aRay length is 5element 0 is aelement 1 is belement 2 is celement 3 is delement 4 is eso we can find "d" in element 0 That 0 at the end of the line above should be a 3. Why isn't it? What am I missing here? Link to comment Share on other sites More sharing options...
Ingolme Posted November 18, 2015 Share Posted November 18, 2015 This is an assignment. You're setting all the elements in the array to "d" aRay[y]='d' Also, in Javascript there is no endif statement. Code within the if() block should be wrapped in { curly braces } Link to comment Share on other sites More sharing options...
george Posted November 18, 2015 Author Share Posted November 18, 2015 Thanks, got it Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now