Basic Algorithm Scripting - Finders Keepers

Is this coding appropriate?

Your code so far

function findElement(arr, func) {
  for (let i = 0; i < arr.length; i++){
    let num = arr[i];
  if (func(num) === true) {
  return num;

console.log(findElement([1, 2, 3, 4], num => num % 2 === 0));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Finders Keepers

Link to the challenge:

You should format your code, but yes, that is a reasonable solution for this challenge.

format my code? What do you mean specifically? Sorry, I’m completely new to this so I’m not sure how exactly do programmers formatting their code usually do.

In all of the code examples you’ve been shown in the challenges, whitespace and {}s are used to show the logical structure of the code.

Your {} don’t have consistent formatting.

function myFunction(arg) {
  for (let i = 0;...) {
    if (...) {
      // more code

Correct code is the #1 priority. Code that is easy to read and change is the #2 priority.

1 Like

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