JRS: In article <ch**********@hercules.btinternet.com>, dated Sat, 11
Sep 2004 14:54:12, seen in news:comp.lang.javascript, badstyle <phatwap-
sp****@yahoo.co.uk> posted :
Can this be refined further to be more efficient?
Yes.
function shout()
{
if (isNaN(document.form1.entry.value)==true) {
alert("please only enter numbers for an answer")}
else
{
alert("the new number is: "+(+document.form1.entry.value+5))}
}
also what would be the correct structure as to make the script more legible
to regular and proficient writers of JS?
"Never" use ==true (except as an indicator of ignorance).
"Numbers" includes such as -1.2345e6, 5e9999, funf-und-funfzig, MCMXLIV,
0x3F5. Perhaps you mean decimal digits? isNaN is generally an
inadequate test. See my js-valid.htm.
Indent two or three spaces, consistently, for each currently-unfinished
language construct.
Use var Ent = document.form1.entry
Omit +( and one ) . Put spaces around concatenating + .
Reword the failure alert.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.