Basic Algorithm Scripting - Finders Keepers

This code is passing when it finds something . It does not pass when you don’t find something.

  **Your code so far**
function findElement(arr, func) {
let length=arr.length;
let first=0;
let test=undefined;
for (let i=0; i<length && test==undefined; i++) {
  if (func(arr[i])) {
  if (test=true) {
    return first;
  } else {return test;}

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

The system generated the above summary, but here is what I find from my Chrome browser:
Version 103.0.5060.134 (Official Build) (64-bit)

Here is my OS:

Edition Windows 11 Pro
Version 21H2
Installed on ‎5/‎20/‎2022
OS build 22000.795
Experience Windows Feature Experience Pack 1000.22000.795.0

Here is my system:

Device name Tonys2022DellPrecision7760
Processor 11th Gen Intel(R) Core™ i9-11950H @ 2.60GHz 2.61 GHz
Installed RAM 64.0 GB (63.2 GB usable)
Device ID E8F61146-8933-4AEB-82BE-EDB4116034FC
Product ID 00355-60711-00677-AAOEM
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Challenge: Basic Algorithm Scripting - Finders Keepers

Link to the challenge:

What do you think this line is doing?

I forgot about == vs. =. Thanks.

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