/    Sign up×
Community /Pin to ProfileBookmark

Need some help with error handling..

Here is my assignment and I am a little confused. I barely know any JavaScript so this is kind of overwhelming.

Write JS 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 JS statements needed to check if the character is not a number or a non-alphanumeric character, or if you throw an error message.

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JavaMonauthorApr 06.2012 — Here is what I got for the first part tell me what I can change to fix it please

<script type="text/javascript">

function validateNumber(formObject) {

try {

var number = formObject.value;

var numberCheck = ?

if (numberCheck.test(number) = false)

throw "One or more of the numbers

you entered

appear to be not valid.";

}

catch(numberError) {

window.alert(numberError)

return false;

}

return true;

}

</script>
Copy linkTweet thisAlerts:
@JavaMonauthorApr 07.2012 — K so here is what I got now for the first question would this work

<script type="text/javascript">

function validateNumber(formObject) {

var x=prompt("0","");

try

{

if(x>10)

{

throw "er1";

}

else if(x<0)

{

throw "er2";

}

else if(isNaN(x))

{

throw "er3";

}

}

catch(er)

{

if(er=="er1")

{

alert("Error: The value is too high");

}

if(er=="er2")

{

alert("Error: The value is too low");

}

if(er=="er3")

{

alert("Error: The value is invalid");

}

}

</script>
Copy linkTweet thisAlerts:
@JavaMonauthorApr 07.2012 — for the 2nd part it need to be like this

<script>

function handler(event) {

alert(event);

}

</script>


but I dont know what to do with that
Copy linkTweet thisAlerts:
@PadonakApr 08.2012 — Here is what I got for the first part tell me what I can change to fix it please

<script type="text/javascript">

function validateNumber(formObject) {

try {

var number = formObject.value;

var numberCheck = ? // here goes a regular expression - something like /[d]{1,}/g;

if (numberCheck.test(number) =[B][COLOR="Red"]=[/COLOR][/B]false)

throw "One or more of the numbers

you entered

appear to be not valid.";

}

catch(numberError) {

window.alert(numberError)

return false;

}

return true;

}

</script>[/QUOTE]


for the very first sight these 2 corrections must be done
×

Success!

Help @JavaMon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...