Re: Number problem



JRS: In article <#Y85WdxRFHA.3988@xxxxxxxxxxxxxxxxxxxx>, dated Fri, 22
Apr 2005 10:46:09, seen in news:microsoft.public.scripting.vbscript,
Lasse Edsvik <lasse@xxxxxxxxxx> posted :

>Im trying to create a function that returns a letter........
>
>The function gets and int......
>
>if x between 1 and 3 then letter = A
>if x between 4 and 6 then letter = B
>if x between 7 and 9 then letter = C
>
>is there some smart way to do this without all the if's?

The numbers between those numbers are 2, 5, and 8 (assuming UK English,
as you are a neighbour) - thus Chr(65+(x-2)/3).

OTOH, if "between" is to include the end values, then note that
for x = 1 to 9 : document.write Chr(65+(x-1)\3) : Next
-> AAABBBCCC

Note : the reverse of Chr() is Asc(); so 65 can be written more
obviously as Asc("A") .

--
© 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.
.



Relevant Pages

  • Re: explain what this means
    ... function getObj{var T ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: beginner: regex how to check that value is only numbers
    ... ignorant generally intend. ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: get ip
    ... ISTM you have a colon too many. ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ... Prev by Date: ...
    (microsoft.public.scripting.jscript)
  • Re: Convert to VBScript to JavaScript ?
    ... ISTM add 7 for next Friday. ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: time zone
    ... One need only go back by the 0..6 days given by getDay() from the last ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ... Prev by Date: ...
    (comp.lang.javascript)