Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active June 1, 2019 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisonmalone/f9b1b88628f380cfa36d2185846dbfe5 to your computer and use it in GitHub Desktop.
Save harrisonmalone/f9b1b88628f380cfa36d2185846dbfe5 to your computer and use it in GitHub Desktop.
try catch and throw challenge for m0119
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