paulman888888 Posted October 3, 2009 Share Posted October 3, 2009 hi; First off thankyou for reading this; Below is code example I[0] = new Array(); I[0][0] = 100; I[0][1] = ''; I[0][2] = '0'; I[0][3] = new Array(); I[0][3][0] = new Array('Administration','',0,0,1); I[0][3][1] = new Array('Finance','',0,0,1); I[0][3][2] = new Array('Sales','Yes, that\'s right. The Sales Department deals with all sales enquiries.',1,100,1); I[0][3][3] = new Array('Customer Services','',0,0,1); I am trying to move away from PHP and start getting more in javascript. I know what i would do in PHP and i know what to do for the first part of the javascript. foreach(i as question){ now am stuck } Also can someone recomend some good sites to learn from not w3school please! Thankyou Paul Quote Link to comment Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 I am trying to move away from PHP and start getting more in javascript. I know what i would do in PHP and i know what to do for the first part of the javascript. foreach(i as question){ now am stuck } I'm not really seeing a question here (other than any good resources), it looks like you wanted to ask something about the code, but nothing ever really is... Am I being blind or did you get sidetracked whilst writing the post like I often do?! Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted October 3, 2009 Author Share Posted October 3, 2009 Yes; i did get abit side tracked. Every time i wrote a word i thought i could do something to make it work. The Question then; i need to compare the 4th parameters to see which one is the highest number. Then show the 1st parameter example I[0][3][0] = new Array('Administration','',0,0,1); I[0][3][1] = new Array('Finance','',0,0,1); I[0][3][2] = new Array('Sales','Yes, that\'s right. The Sales Department deals with all sales enquiries.',1,100,1); I[0][3][3] = new Array('Customer Services','',0,0,1); I want to compare these arrays and check for the 4th parameter and show the 2nd one for the highest. So this should show Sales is the correct answer! Thankyou Paul Once again if i have done something wrong its because i keep trying (and failing) with every new idea which pops into my head. I have prove readed though so it should be fine. Quote Link to comment Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 As I said before, I really don't know JavaScript (not even sure how to test my code, lol) and it difficult to be sure without knowing exactly what the array stores, but I think this logic might be what your after (syntax probably not perfect)... var questionID = 3; var highestID = 0; for(var i = 0; i < 4; i++) { if(a[0][questionID][i] > a[0][questionID][highestID]) { higestID = i; } } Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted October 7, 2009 Author Share Posted October 7, 2009 Thank you cags. I've had an idea; (Based on what i know about PHP) I thought that the require number can be set then found instead of finding the highest Idea below <html><head><title>Hack Them Questions</title></head><body><script type="text/javascript"> var target =100;// number to find var q = 4//number of possible answers to search var i = 0; I[0][3][0] = new Array('Administration','',0,0,1); I[0][3][1] = new Array('Finance','',0,0,1); I[0][3][2] = new Array('Sales','Yes, that\'s right. The Sales Department deals with all sales enquiries.',1,100,1); I[0][3][3] = new Array('Customer Services','',0,0,1); for(i < q) { if(I[0][3][i][4] == target){ document.write(I[0][3][i][1]); } i=i+i; } </script></body></html> It doesn't work and i will be great full for any help. Thankyou Paul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.