Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active July 26, 2022 21:42
Show Gist options
  • Save acidtone/385b2f850d4881364ac7b0da320f239a to your computer and use it in GitHub Desktop.
Save acidtone/385b2f850d4881364ac7b0da320f239a to your computer and use it in GitHub Desktop.
JS Activity: Test if a value is in an array

JS Activity: Testing for an array item

When an array contains primitive values, you can use the Array.includes() method to test if a value exists within that array.

Instructions

  1. Download or fork/clone this Gist into your workspace.
  2. Using conditional statements and the Array.includes() method, test if the entered command line value exists in the characterClasses array:
    • If true log the following to the console:

      "[inputted value]" is a valid Character Class!`
      
    • If false log the following to the console:

      "[inputted value]" is NOT a valid Character Class! Please try again.`
      

Spoilers

A potential answer to this activity.

// Accept command line input
const inputValue = process.argv[2];
// Define data array
const characterClasses = [
'fighter',
'wizard',
'rogue',
'barbarian',
'bard'
];
// Your code goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment