Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /* 
Context:  I was writing an extensible component for recaptcha validation for my scavenger hunt.
The component accepts 9 images that make up the recaptcha.  The component also accepts an array of indices that represent which photos must be clicked on in order to satisfy the recpatcha challenge.
- `status` is a variable in the component that reflects which picture has been clicked on.  `true` === clicked on, `false` === not clicked on
- `trueValidation<X>` is a variable that gets passed into the component that defines what a successful status is

Write a function, `recaptchaCheck()` to validate if the given status passes the recaptcha check.  The function should console.log "true" if the status passes the check, and "false" if not.
- Bonus for using `Array.reduce()`

`recaptchaCheck(status, trueValidation1)` --> logs "true"
`recaptchaCheck(status, trueValidation2)` --> logs "false"
`recaptchaCheck(status, trueValidation3)` --> logs "false"
*/

const status = {
  1: true,
  2: false,
  3: true,
  4: false,
  5: true,
  6: false,
  7: true,
  8: false,
  9: true
};
const trueValidation1 = [0, 2, 4, 6, 8]; // true
const trueValidation2 = [1, 3, 5, 7, 9]; // false
const trueValidation3 = [0, 2, 4]; // false

const recaptchaCheck = (status, trueValidation) => {
  // your answer
  const statusArr = Object.values(status);

  //   statusArr.map((stat, i) => {
  //         const incl = trueValidation.includes(i);
  //     if ((stat && incl) || (!stat && !incl)) {
  //       return i
  //     }
  //   })

  for (let i = 0; i < statusArr.length; i++) {
    const stat = statusArr[i];
    const incl = trueValidation.includes(i);
    if ((stat && incl) || (!stat && !incl)) {
      continue;
    } else {
      return false;
    }
  }
  return true;
};

// call function
console.log(recaptchaCheck(status, trueValidation3));

              
            
!
999px

Console