This is a potential answer to the exercise: Test for an array item.
- Try validating the user input before testing:
inputValue
value missing: "Please enter a Character Class";
This is a potential answer to the exercise: Test for an array item.
inputValue
value missing: "Please enter a Character Class";// Accept command line input | |
const inputValue = process.argv[2]; | |
// Define data array | |
const characterClasses = [ | |
'fighter', | |
'wizard', | |
'rogue', | |
'barbarian', | |
'bard' | |
] | |
// Test if the entered string matches a value in characterClasses | |
if (characterClasses.includes(inputValue)) { | |
console.log(`"${inputValue}" is a valid Character Class!`); | |
} else { | |
console.log(`"${inputValue}" is NOT a valid Character Class! Please enter another Character Class.`); | |
} |