Jump to content

[SOLVED] Anoher compare question!


paulman888888

Recommended Posts

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

Link to comment
Share on other sites

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?!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
  }
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.