ASE Labs
Welcome Guest. Please register or log in now. There are 296 people online (0 Friends).
  • Home
  • Articles
  • News
  • Forum
  • Register/Login

JavaScript Help

There are 7 messages in this topic Watch this topic for replies Subscribe to this topic
Add Reply Back to forum "Tech Support" Back to Index
stinger608 Avatar Joined: December 5, 2008 Status: Offline Posts: 169 Rep: PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 1 (4217)
JavaScript Help Old Wed Oct 27, 2010 10:05:22 PM #138322 Perm Link
Hey everyone, just getting started in JavaScript, and basically it is kicking my butt so far. It seems that the class is more for an intermediate learner than a beginner

None the less, I have this assignment due, and many of us students are completely in the dark here. LOL Anyhow, this is the question we must answer.

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.

Any help would be much appreciate
Reply Quote Multi-Quote-Off Send PM Profile
Tornado Avatar Retro Grade Joined: August 16, 2003 Status: Offline Posts: 2958 Rep: PIP Level 3 (74215)PIP Level 2 (74215)PIP Level 2 (74215)PIP Level 2 (74215)PIP Level 2 (74215)
(No Title) Old Wed Oct 27, 2010 11:48:03 PM #138324 Perm Link
In response to stinger608 #138322
I haven't done any programming since my second semester of college, but let me see if I can dig up any of my old notes. I'm pretty sure I can do it from memory, but I wouldn't have the ability to test it until I went to school tomorrow.

Edited at Wed Oct 27, 2010 11:48:16 PM
Michael: Jodie, how's my schedule look for today?
Jodie: You've got a conference and dinner party at the Japanese Embassy regarding wildlife protection.
Michael: Oh, yeah...sorry, but I'll have to cancel that. I'm heading out to save America!
Reply Quote Multi-Quote-Off Send PM Profile
Aron Schatz Avatar 2014: Year of change. Joined: August 3, 2001 Status: Offline Posts: 10753 Rep: PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 1 (332767)
(No Title) Old Thu Oct 28, 2010 8:35:39 AM #138331 Perm Link
In response to stinger608 #138322
try/catch blocks are for exceptions. You could do type checking for this assignment and Javascript is a loosely typed language.

What code have you got so far?

2014 is going to be a good year. More content, more streamlining. Be a part of history!
Reply Quote Multi-Quote-Off Send PM Profile
stinger608 Avatar Joined: December 5, 2008 Status: Offline Posts: 169 Rep: PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 1 (4217)
(No Title) Old Thu Oct 28, 2010 6:55:12 PM #138351 Perm Link
So far, this is what I have.


Quote

var x=prompt("Enter a number between 0 and 10:","");
try
{
if(x>10)
{
throw "Err1";
}
else if(x<0)
{
throw "Err2";
}
else if(isNaN(x))
{
throw "Err3";
}
}
catch(er)
{
if(er=="Err1")
{
alert("Error! The value is too high");
}
if(er=="Err2")
{
alert("Error! The value is too low");
}
if(er=="Err3")
{
alert("Error! The value is not a number");
}


Does it look okay Aron?
Reply Quote Multi-Quote-Off Send PM Profile
Tornado Avatar Retro Grade Joined: August 16, 2003 Status: Offline Posts: 2958 Rep: PIP Level 3 (74215)PIP Level 2 (74215)PIP Level 2 (74215)PIP Level 2 (74215)PIP Level 2 (74215)
(No Title) Old Thu Oct 28, 2010 8:38:26 PM #138476 Perm Link
Have you tried compiling and testing it? Just looking at it I can see something that I would do differently, but I'm not sure if the way you have done it is actually wrong.

Michael: Jodie, how's my schedule look for today?
Jodie: You've got a conference and dinner party at the Japanese Embassy regarding wildlife protection.
Michael: Oh, yeah...sorry, but I'll have to cancel that. I'm heading out to save America!
Reply Quote Multi-Quote-Off Send PM Profile
stinger608 Avatar Joined: December 5, 2008 Status: Offline Posts: 169 Rep: PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 2 (4217)PIP Level 1 (4217)
(No Title) Old Thu Oct 28, 2010 9:15:06 PM #138478 Perm Link
In response to Tornado #138476

Said By Tornado

Have you tried compiling and testing it? Just looking at it I can see something that I would do differently, but I'm not sure if the way you have done it is actually wrong.


Share the suggestion Tornado. Please, this is very new too me, and I am having somewhat of a tough time with this language.......Jeez, not even sure why to be honest. Maybe I have gotten too used to HTML/CSS, Joomla, and WordPress. I would really like to understand this better, as it really enhances web sites, and is of course executed on the users end, taking a large burden off the server end.
Reply Quote Multi-Quote-Off Send PM Profile
Aron Schatz Avatar 2014: Year of change. Joined: August 3, 2001 Status: Offline Posts: 10753 Rep: PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 3 (332767)PIP Level 1 (332767)
(No Title) Old Thu Oct 28, 2010 11:09:23 PM #138487 Perm Link
I'll try it out when I get back.

You learn something when you do web programming... never trust the client... EVER. Javascript is all well and good to handle certain ease of use (on the client), but all true functionality comes from the backend.

Regardless of how much validation you put into Javascript, you always do server side checks.

I still don't know why he wants you to use try/catch for this. I mean, exceptions are nice for stuff, but not this.

I'll give you an example of when to use exceptions. In a strong typed language (C++), you can use exceptions to give status of a function even if the function returns an integer. You could throw exceptions for improper inputs and other such stuff. That's when you do try{function();}catch(e){echo "ERROR!".e->errorText;} (Pseudo code).

Edited at Thu Oct 28, 2010 11:12:23 PM
2014 is going to be a good year. More content, more streamlining. Be a part of history!
Reply Quote Multi-Quote-Off Send PM Profile
Page: [1]
Add Reply Back to forum "Tech Support" Back to Index
Login
Welcome Guest. Please register or log in now.
Forgot your password?
Navigation
  • Home
  • Articles
  • News
  • Register/Login
  • Shopping
  • ASE Forums
  • Anime Threads
  • HardwareLogic
  • ASE Adnet
Latest News
  • Kingston HyperX Cloud 2 Pro Gaming Headset Unboxing
  • Synology DS415+ Unboxing
  • D-Link DCS-5020L Wireless IP Pan/Tilt IP Camera
  • Actiontec WiFi Powerline Network Extender Kit Unboxing
  • Durovis Dive Unboxing
  • Bass Egg Verb Unboxing
  • Welcome to the new server
  • Gmail Gets Optional Preview Pane
  • HBO Go on Consoles
  • HP Touchpad Update
Latest Articles
  • D-Link Exo AC2600 Smart Mesh Wi-Fi Router DIR-2660-US
  • HyperX Double Shot PBT Keys
  • Avantree ANC032 Wireless Active Noise Cancelling Headphones
  • ScharkSpark Beginner Drones
  • HyperX Alloy FPS RGB Mechanical Gaming Keyboard
  • D-Link DCS-8300LH Full HD 2-Way Audio Camera
  • Contour Unimouse Wireless Ergonomic Mouse
  • HyperX Cloud Alpha Pro Gaming Headset
  • Linksys Wemo Smart Home Suite
  • Fully Jarvis Adjustable Standing Desk
Latest Topics
  • Hello
  • Welcome to the new server at ASE Labs
  • Evercool Royal NP-901 Notebook Cooler at ASE Labs
  • HyperX Double Shot PBT Keys at ASE Labs
  • Avantree ANC032 Wireless Active Noise Cancelling Headphones at ASE Labs
  • ScharkSpark Beginner Drones at ASE Labs
  • HyperX Alloy FPS RGB Mechanical Gaming Keyboard at ASE Labs
  • D-Link DCS-8300LH Full HD 2-Way Audio Camera at ASE Labs
  • Kingston SDX10V/128GB SDXC Memory at ASE Labs
  • What are you listening to now?
  • Antec Six Hundred v2 Gaming Case at HardwareLogic
  • Sans Digital TR5UTP 5-Bay RAID Tower at HardwareLogic
  • Crucial Ballistix Smart Tracer 6GB PC3-12800 BL3KIT25664ST1608OB at HardwareLogic
  • Cooler Master Storm Enforcer Mid-Tower Gaming Case at HardwareLogic
  • Arctic M571-L Gaming Laser Mouse at ASE Labs
  • Contour Unimouse Wireless Ergonomic Mouse at ASE Labs
Press Release
  • Huntkey Has Launched Its New Power Strips with USB Chargers on Amazon US
  • Inspur Releases TensorFlow-Supported FPGA Compute Acceleration Engine TF2
  • Hot Pepper Introduces Spicy New Smartphones in US Markets
  • Sharp Introduces New Desktop Printers For The Advanced Office
  • DJI Introduces Mavic 2 Pro And Mavic 2 Zoom: A New Era For Camera Drones
  • DJI Introduces Mavic 2 Pro And Mavic 2 Zoom: A New Era For Camera Drones
  • Fujifilm launches "instax SQUARE SQ6 Taylor Swift Edition", designed by instax global partner Taylor Swift
  • Huawei nova 3 With Best-in-class AI Capabilities Goes on Sale Today
  • Rand McNally Introduces Its Most Advanced Dashboard Camera
  • =?UTF-8?Q?My_Size_to_Showcase_Its_MySizeId=E2=84=A2_Mobil?= =?UTF-8?Q?e_Measurement_Technology_at_CurvyCon_NYC?=
Home - ASE Publishing - About Us
© 2010 Aron Schatz (ASE Publishing) [Queries: 19 (9 Cached)] [Rows: 369 Fetched: 64] [Page Generation time: 0.011307001113892]