helpneeded22 Posted July 27, 2012 Share Posted July 27, 2012 (edited) I am brand new to Javascript, but I do have some programming experience. My code is not working and the only reason I can think of is that JS must not be able to evaluate an array in an IF statement? Here is a sample code: <script type="text/javascript"> var mini01=["AMIRI","Rare","Medium","on","Announced","July 7, 2012"];var rarecolor="#000000";if (mini01[1]=="Common") { rarecolor="#008000"; } elseif (mini01[1]=="Uncommon") { rarecolor="#0000ff"; } else { rarecolor="#ffffff"; }document.write('<font color="' + rarecolor +'">');document.write(mini01[1]); </script> Nothing outputs. Any suggestions? (Note: I do close the FONT tag in html after the script) Edited July 27, 2012 by helpneeded22 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 27, 2012 Share Posted July 27, 2012 You need to use "==" or "===" to compare values, the "=" operator assigns a value. You're changing the value of mini01[1], not checking it. Link to comment Share on other sites More sharing options...
helpneeded22 Posted July 27, 2012 Author Share Posted July 27, 2012 I think I have it working now. I noted that the "elseif" should be "else if". When I deleted the lines with "else if" it still failed to function with the "else" condition. When I remove the "else" then it all works. 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