-4

I have been given these two tasks. I’m not asking you to do the tasks for me; what I need is greater understanding.

  1. Write JavaScript™ code that anticipates and handles an error for an expected numeric field. This code is executed on keypress, and the entered value is saved for you in a variable called enteredChar. Include the try block of JavaScript™ statements needed to check if the character is not a number or a non-alphanumeric character, or if you throw an error message.

  2. Write a custom error handling JavaScript™ function called processErrors that handles a custom error by assigning it to the onerror event handler. Include the block of JavaScript™ statements needed to pass the arguments sent by the JavaScript™ interpreter into the processErrors function, send an alert message with the agreements, return, and write the event handler that calls the processErrors function.

What I am supposed to do? I am brand new to JavaScript and I am unsure what I have been asked to do.

I think the first one is asking me to write a code that stops anything but numbers and letters from running in the program?

The second one I think is asking me to code for some kind of error, but I am not sure what.

I am looking for clarification.

Community
  • 1
  • 1

2 Answers2

2

If you are unclear of what is being asked of you a good first step is to go back to who gave you the requirements and clarify them there.

brandonbradley
  • 607
  • 5
  • 7
1
  1. See Best way to track onchange as-you-type in input type="text"?. So your going to listen to a text input field as you type, and then evaluate if the character is a number. See Check if character is number?. They want you to wrap that in a try/catch.

  2. They now want you to process the "catch" (the error) from number 1 called 'processErrors'. See how to catch ALL javascript errors with window.onerror? (including dojo).

Wow I almost managed to link everything back to stack overflow. +10 ;)

Good luck

Community
  • 1
  • 1
Mark
  • 2,429
  • 20
  • 20
  • Ok, I am very much a beginner and I do not understand what you mean when you said "listen to a text input" or "wrap to try/catch"? Can you explain it a little better? – Snowkissau Jan 24 '14 at 20:48
  • 1
    http://www.w3schools.com/js/js_events_examples.asp Good place to start anyway. – Mark Jan 24 '14 at 20:53
  • 1
    @Mark no, it's not. Mozilla Developer Network should be used instead – John Dvorak Jan 24 '14 at 20:56