Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Refactor complex code to function</strong></p> <p>If you have complex if statements try and wrap them up in functions. So </p> <pre><code>(flightDestinations[i] == yourDestination &amp;&amp; yourAirline == 'Any airline' &amp;&amp; yourFare == 'Any price') </code></pre> <p>could become </p> <pre><code>function YourDestinationIsTheSameForAnyAirlineOrPrice(flightDestination, yourDestination, yourAirline, yourFare){ return flightDestination == yourDestination &amp;&amp; yourAirline == 'Any airline' &amp;&amp; yourFare == 'Any price'; } // And called from if if (YourDestinationIsTheSameForAnyAirlineOrPrice(flightDestinations[i], yourDestination, yourAirline, yourFare)) {} </code></pre> <p>Rather than trying to decipher the if statement you have a function name telling you what it does.</p> <p><strong>Use an object over multiple arrays</strong></p> <p>Specific to your example I would also try and create a single flight object that contains the destination, time and airline. eg:</p> <pre><code>var flight = { destination = "London", operator = "BA", time = "18:00 UTC", fare = "£239829" } </code></pre> <p>This should make the code more readable than using multiple arrays. Example:</p> <pre><code>destinationTime = flightTimes[i]; destinationOperator = flightOperators[i]; destinationFare = flightFares[i]; message += destinationTime + ' ' + destinationOperator + '. £' + destinationFare + '&lt;BR&gt;'; // Using an object message += flight.Time + ' ' + flight.Operator + '. £' + flight.Fare + '&lt;br /&gt;'; </code></pre> <p><strong>Return early</strong></p> <p>Finally I would break out of the function as soon as possible. So use:</p> <pre><code>if (yourDestination == 'Choose your destination') { displayMessage('&lt;B&gt;Please choose a destination city from the Destination menu and then click Find flights again.&lt;/B&gt;'); return; } </code></pre> <p>instead of an if...else. I personally find this more readable, so feel free to ignore this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload