ASE Labs
Welcome Guest. Please register or log in now. There are 12 people online (0 Friends).
  • Home
  • Articles
  • News
  • Forum
  • Register/Login
You are at ASE Labs » Forum Index » Technology » Tech Support » JavaScript Help

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 Problem? Joined: August 16, 2003 Status: Offline Posts: 2939 Rep: PIP Level 3 (69742)PIP Level 2 (69742)PIP Level 2 (69742)PIP Level 2 (69742)PIP Level 2 (69742)
(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 OS Xtreme FTW Joined: August 3, 2001 Status: Offline Posts: 10716 Rep: PIP Level 3 (312720)PIP Level 3 (312720)PIP Level 3 (312720)PIP Level 2 (312720)PIP Level 2 (312720)
(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?

The new OS Xtreme theme is out in FORCE. Try it now and be amazed. It is the best style we've got.
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 Problem? Joined: August 16, 2003 Status: Offline Posts: 2939 Rep: PIP Level 3 (69742)PIP Level 2 (69742)PIP Level 2 (69742)PIP Level 2 (69742)PIP Level 2 (69742)
(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 OS Xtreme FTW Joined: August 3, 2001 Status: Offline Posts: 10716 Rep: PIP Level 3 (312720)PIP Level 3 (312720)PIP Level 3 (312720)PIP Level 2 (312720)PIP Level 2 (312720)
(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
The new OS Xtreme theme is out in FORCE. Try it now and be amazed. It is the best style we've got.
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
  • Welcome to the new server
  • Gmail Gets Optional Preview Pane
  • HBO Go on Consoles
  • HP Touchpad Update
  • Happy System Administrator Day!
  • Apple Releases OS X 10.7 Lion
  • More Android Apps Found to be Malware
  • This Weeks News
  • Happy Birthday USA!
  • Windows Phone Gets Angry Birds, Custom Rings Coming To Mango
Latest Articles
  • Sapphire Edge HD4 Mini PC
  • Logitech G710+ Mechanical Gaming Keyboard
  • EnerPlex Kickr IV And Jumpr Solar Power Pack
  • Kingston Wi-Drive
  • Kingston SDX10V/128GB SDXC Memory
  • In-Win K1 All In One Convertible Case
  • Kingston MobileLite G3 USB3 SDXC Card Reader
  • Synology DS712+ Network Application Server
  • Rapoo Wireless Touchpad Keyboard E9080
  • Netgear NeoTV NTV200 Streaming Player
Latest Topics
  • Air Jordan Shoes: The most appropriate Sports activities Trunk
  • Nike Free Run game shoes and boots
  • Random Fact of the Day
  • What are you listening to now?
  • Watch Man of Steel 2013 Online Free Full Movie in HD
  • Handmade Jewelry With Big Discounts at Aypearl.com Now
  • New Spam controls coming soon
  • Hassan Rouhani wins Iran presidency
  • FULL MOVIE - Watch MAN OF STEEL Online Free Stream in HD
  • No decision on arming Syrian rebels
  • How to stop a person from bullying you ?
  • A QUESTION!! PLEASE HELP!
  • End of the Road.
  • Story Time!
  • A Sims RP? >.>
  • тнє нαηgιηg тяєє
Advertisement
Advertisement
Affiliate Reviews
  • Fractal Design Arc Midi R2 Case Review at Pro-Clockers
  • EVGA Introduces SuperNOVA 1300 G2 PSU at Hardware Secrets
  • Faster Acer C7 Chromebook at Walmart for USD 199 at Hardware Secrets
  • Qt 5.1 Release Candidate 1 Has Arrived at Phoronix
  • In-Fighting Continues Over Mir On Non-Unity Ubuntu at Phoronix
  • ASRock Z87 Extreme4 Motherboard at Hardware Secrets
  • Subversion 1.8 Presents New Features at Phoronix
  • MSI GTX 770 Lightning 2 GB Review at techPowerUp!
  • Thermaltake Urban S21 Elegant Mid Tower Review at Pro-Clockers
  • LLVM 3.3 Officially Released at Phoronix
  • LLVM/Clang Now Uses Loop Vectorizer At New Levels at Phoronix
  • Intel GPU Driver Tries To Rip Out FBDEV Support at Phoronix
  • Coreboot Doing AMD USB 3.0, Q35 QEMU Emulation at Phoronix
  • Super Talent Introduces Ram Disk Series USB 3.0 Flash Drives at Hardware Secrets
Press Release
  • Finesse Solutions Launches Next Generation SmartGlass 3L Bioreactors for Cell Culture and Fermentation
  • Samsung Galaxy S4 Gets Two Sleek and Stylish 2nd Generation WiQiQi Wireless Chargers For Desktop and Car Use
  • Northrop Grumman Delivers Open-Architecture Software Development Kit to Interested Parties Following AMDR Industry Day
  • Entrust First North American CA to Complete Audit for New CA/Browser Forum SSL Baseline Requirements
  • Customized for Your Listening Pleasure: Altec Lansing's New Bluetooth Speaker 'The Jacket' Offers Eye Candy for Audiophiles
  • ViaSat Ka-band In-flight System Will Be New Option for Boeing Commercial Aircraft
  • Ubitus Powers LG U+ C-Games Cloud Gaming Service on Google TV Set-Top Box
  • Sygic Is Celebrating 30 Million Downloads With Special Summer Offer
  • BSI Certification Positions Blancco as Germany's First Nationwide Provider of Data Erasure for Public Agencies
  • Technology Pioneer Jussi Kiviniemi Joins Ekahau to Innovate the Wi-Fi Tools Product Line
Home - ASE Publishing - About Us
© 2010 Aron Schatz (ASE Publishing) [Queries: 18 (9 Cached)] [Rows: 368 Fetched: 63] [Page Generation time: 0.034327030181885]