-
-
Save harrisonmalone/f9b1b88628f380cfa36d2185846dbfe5 to your computer and use it in GitHub Desktop.
try catch and throw challenge for m0119
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ptv = [ | |
"Alamein", | |
"Belgrave", | |
"Craigieburn", | |
"Cranbourne", | |
"Flemington", | |
"Frankston", | |
"Glen Waverley", | |
"Hurstbridge", | |
"Lilydale", | |
"Mernda", | |
"Pakenham", | |
"Sandringham", | |
"Stony Point", | |
"Sunbury", | |
"Upfield", | |
"Werribee", | |
"Williamstown" | |
] | |
// write a function that takes an index value as an argument and returns one particular ptv line | |
// inside the function throw an error if the index number passed as an argument is incorrect, say if you pass 20 as an argument, there is no 20th element in the array so it's undefined, still return the ptv line if the correct argument is passed | |
// invoke this function inside of a try and catch statement, if the correct index is passed console.log the train line in the try, if the incorrect index is passed console.log the error | |
// create your own custom error using a constructor function, refer to these docs for help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw#Examples |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment