Two dimensional array as parameter

i have a problem that i am not yet able to solve that is asked for me to create a function.

the exercise goes like this:
Write a function named getValidPassword that takes a two dimensional array as parameter.

Each entry in the array represents a passcode. You need to find the passcode that has no odd digits and return it from your function.

Here’s an example:

var loggedPasscodes =[
    [1, 4, 4, 1],
    [1, 2, 3, 1],
    [2, 6, 0, 8],
    [5, 5, 5, 5],
    [4, 3, 4, 3, 8],
    [4, 3, 2, 3, 9]
];

getValidPassword(loggedPasscodes) // returns the array: [2, 6, 0, 8]

my code is:

function getValidPassword (loggedPasscodes){
  for(let i= 0; loggedPasscodes.length > i;i++){
      let passcode = loggedPasscodes [i];
      for (let j = 0;passcode.length > j; j++){
          if(passcode [j] % 2 !== 0){
              break;
          }
          
      }

        return passcode;
  }     
   
}                  
                                
                                
                                
 var loggedPasscodes=[
    ["1","4","4","1"],
    ["1", "2", "3", "1"],
    ["2","6", "0","8"],
    ["5", "5", "5", "5"],
    ["4","3", "4", "3"],
];
console.log(getValidPassword(loggedPasscodes));

and i get the error:

Code is incorrect
Function getValidPassword is not working as requested.
[

“1”,

“4”,

“4”,

“1”

]

can someone help?

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

thank you very much and sorry about that

can you descrive in your own words what your function is doing?

what do you think this if statement will do when the first number it sees is odd?
And what is the next line of code that will be executed in this case?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.