title: JavaScript - Take A Ten Minute Walk - How to Access Array Elements Properly
body: <p>If you're not familiar with this challenge, here are the instructions:</p>
  
  <p><a href="https://www.codewars.com/kata/54da539698b8a2ad76000228/train/javascript" rel="nofollow noreferrer">https://www.codewars.com/kata/54da539698b8a2ad76000228/train/javascript</a></p>
  
  <blockquote>
    <p>You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']). You always walk only a single block in a direction and you know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.</p>
  </blockquote>
  
  <p>So far, I have tried:</p>
  
  <pre><code>function isValidWalk(walk) {
  
    //initiate person starting point
    let person = [0, 0]
    //establish what the ending point must be
    let finalDestination = [0, 0]
  
    let north = [0, 1]
    let east = [1, 0]
    let south = [0, -1]
    let west = [-1, 0]
  
    //as long as the length of the array is 10 or less, continue walk
    for (let i = 0; i &lt;= 10; i++) {
      //if the letter in the array is "n", move north
      if (walk[i] === "n") {
        person + north;
      }
      //if the letter in the array is "e", move east
      if (walk[i] === "e") {
        person + east;
      }
      //if the letter in the array is "s", move south
      if (walk[i] === "s") {
        person + south;
      }
      //if the letter in the array is "w", move west
      if (walk[i] === "w") {
        person + west;
      }
    }
  
    if (person === finalDestination) {
      return true;
    }
    else {
      return false;
    }
  
  }
  </code></pre>
  
  <p>And this is passing 6/9 tests, but it is not returning <code>true</code> for a valid walk. </p>
  
  <p>As you can see, I tried to say that the <code>isValidWalk</code> function should return true if the location of <code>person</code> is equal to the <code>finalDestination</code> variable at the end of their walk. </p>
  
  <p>I know that there are probably other ways to solve this problem, but I would like to continue following the logic that I've established if that's possible. </p>
  
  <p>I'm wondering if my problem is that I'm not accessing the elements in the array correctly? I.e. is <code>walk[i]</code> getting the array elements correctly here?</p>
  
  <pre><code>    if (walk[i] === "n") {
        person + north;
      }
  </code></pre>
  
  <p>That is what should be moving the <code>person</code> around on this imaginary grid but apparently it's not doing anything. What other syntax should I try to access the elements in the array and check if they're equal to "n", "e", "s", and "w"?</p>