Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34317 > unrolled thread
| Started by | super70s <super70s@super70s.invalid> |
|---|---|
| First post | 2017-11-12 07:04 -0600 |
| Last post | 2017-11-13 16:45 -0800 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.javascript
simple question super70s <super70s@super70s.invalid> - 2017-11-12 07:04 -0600
Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-12 14:22 +0000
Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 18:33 +0100
Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-12 20:28 +0000
Re: simple question super70s <super70s@super70s.invalid> - 2017-11-12 15:11 -0600
Re: simple question Andrew Poulos <ap_prog@hotmail.com> - 2017-11-13 13:26 +1100
Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-12 22:39 +0100
Re: simple question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-11-13 01:20 +0000
Re: simple question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-11-13 03:49 +0100
Re: simple question Julio Di Egidio <julio@diegidio.name> - 2017-11-13 16:45 -0800
| From | super70s <super70s@super70s.invalid> |
|---|---|
| Date | 2017-11-12 07:04 -0600 |
| Subject | simple question |
| Message-ID | <super70s-C3F170.07042612112017@reader02.eternal-september.org> |
<head>
<script language="JavaScript">
<!-- Begin
var msg = new Array();
Stamp = new Date();
today = Stamp.getDate();
(messages)
(messages)
(messages)
(messages)
function writeTip() {
document.write(msg[today]);
}
// End -->
</script>
</head>
<body>
<script>writeTip();</script>
</body>
Hi I have a simple question, if I had two of the above scripts on the
same page, how can I distinguish one from the other? thanks
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-12 14:22 +0000 |
| Message-ID | <87375jwp8x.fsf@bsb.me.uk> |
| In reply to | #34317 |
super70s <super70s@super70s.invalid> writes:
> <head>
>
> <script language="JavaScript">
> <!-- Begin
> var msg = new Array();
> Stamp = new Date();
> today = Stamp.getDate();
>
> (messages)
> (messages)
> (messages)
> (messages)
>
> function writeTip() {
> document.write(msg[today]);
> }
> // End -->
> </script>
>
> </head>
> <body>
>
> <script>writeTip();</script>
>
> </body>
>
>
> Hi I have a simple question, if I had two of the above scripts on the
> same page, how can I distinguish one from the other?
You can't, at least not in the way I think you mean. I think you want
to be able to select two messages from two different arrays. To do that
you should make the message array a parameter to your function.
(Personally, I'd do things a little differently but I want to suggest
minimal changes.)
So you have one script element with
function writeTip(msgs) {
document.write(msgs[new Date().getDate()];
}
and then call it with different arrays from two other script elements
(I'll show only one):
<script language=JavaScript>
writeTip([
"dummy",
"Happy first!",
...
"All over for this month."
]);
</script>
No doubt I have lots of typos since this has not been machine checked.
Note how I have avoided variables where possible. If you do need them
you should learn how to avoid them being "global".
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-11-12 18:33 +0100 |
| Message-ID | <4024886.LvFx2qVVIh@PointedEars.de> |
| In reply to | #34319 |
Ben Bacarisse wrote:
> super70s <super70s@super70s.invalid> writes:
>> <script language="JavaScript">
Invalid, thrice. Automatically killfiled because of the second.
>> <!-- Begin
Nonsense.
>> var msg = new Array();
The right-hand side is deprecated in favor of “[]”.
>> Stamp = new Date();
Undeclared variable (“var” or “const” missing), unwise identifier (is not a
constructor).
Use JSHint.
>> today = Stamp.getDate();
Date.prototype.getDate() returns the number of the day of a month, not a
date string.
> function writeTip(msgs) {
> document.write(msgs[new Date().getDate()];
> }
>
> and then call it with different arrays from two other script elements
> (I'll show only one):
>
> <script language=JavaScript>
> writeTip([
> "dummy",
> "Happy first!",
> ...
> "All over for this month."
> ]);
> </script>
>
> No doubt I have lots of typos since this has not been machine checked.
More than that, your code, if obvious syntax errors are corrected, simply
would not do what you think it does.
Also, the HTML is still invalid.
<http://validator.w3.org/>
Head shaking,
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-12 20:28 +0000 |
| Message-ID | <87shdjutqw.fsf@bsb.me.uk> |
| In reply to | #34323 |
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
> Ben Bacarisse wrote:
>
>> super70s <super70s@super70s.invalid> writes:
>>> <script language="JavaScript">
>
> Invalid, thrice. Automatically killfiled because of the second.
>
>>> <!-- Begin
>
> Nonsense.
>
>>> var msg = new Array();
>
> The right-hand side is deprecated in favor of “[]”.
>
>>> Stamp = new Date();
>
> Undeclared variable (“var” or “const” missing), unwise identifier (is not a
> constructor).
>
> Use JSHint.
>
>>> today = Stamp.getDate();
>
> Date.prototype.getDate() returns the number of the day of a month, not a
> date string.
>
>> function writeTip(msgs) {
>> document.write(msgs[new Date().getDate()];
>> }
>>
>> and then call it with different arrays from two other script elements
>> (I'll show only one):
>>
>> <script language=JavaScript>
>> writeTip([
>> "dummy",
>> "Happy first!",
>> ...
>> "All over for this month."
>> ]);
>> </script>
>>
>> No doubt I have lots of typos since this has not been machine checked.
>
> More than that, your code, if obvious syntax errors are corrected,
Are you counting the "..."? (I would not be surprised!) Otherwise I
see only one.
> simply
> would not do what you think it does.
How on Earth do you know that? Obviously I'm guessing a bit about what
the OP wants, but it does what I want!
> Also, the HTML is still invalid.
Of course. What possible value could there be in my adding the missing
title element to the OP's HTML?
> <http://validator.w3.org/>
>
>
> Head shaking,
How pompous can you be?
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | super70s <super70s@super70s.invalid> |
|---|---|
| Date | 2017-11-12 15:11 -0600 |
| Message-ID | <super70s-5A86FC.15114312112017@reader02.eternal-september.org> |
| In reply to | #34325 |
In article <87shdjutqw.fsf@bsb.me.uk>, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: > > <http://validator.w3.org/> > > > > > > Head shaking, > > How pompous can you be? I got the script off the web a very long time ago but it still works fine in the latest browsers, when it doesn't any longer I might pay attention to his sound and fury (signifying nothing).
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2017-11-13 13:26 +1100 |
| Message-ID | <f8udnQnUOaZ_n5THnZ2dnUU7-UPNnZ2d@westnet.com.au> |
| In reply to | #34326 |
On 13/11/2017 8:11 AM, super70s wrote: > In article <87shdjutqw.fsf@bsb.me.uk>, Ben Bacarisse > <ben.usenet@bsb.me.uk> wrote: > >> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >>> <http://validator.w3.org/> >>> >>> >>> Head shaking, >> >> How pompous can you be? > > I got the script off the web a very long time ago but it still works > fine in the latest browsers, when it doesn't any longer I might pay > attention to his sound and fury (signifying nothing). You could be proactive and not wait for, say, a client wondering why their web site suddenly no longer "works". In fact if I was the client and I found out that you'd been warned and chose to do nothing then I been quite a bit peeved. Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-11-12 22:39 +0100 |
| Message-ID | <1926921.irdbgypaU6@PointedEars.de> |
| In reply to | #34325 |
Ben Bacarisse wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: > > Are you counting the "..."? (I would not be surprised!) Otherwise I > see only one. The dots are the obvious syntax errors, yes. >> simply would not do what you think it does. > > How on Earth do you know that? In your favor, I have assumed reasonable thinking, but obviously I was wrong. > Obviously I'm guessing a bit about what the OP wants, but it does what > I want! Oh, really? And what would that be? >> Also, the HTML is still invalid. > > Of course. What possible value could there be in my adding the missing > title element to the OP's HTML? The missing “title” element is not the problem because this code needs to be inserted in an HTML document that is supposed to have a “title” element already; the missing “type” attribute (HTML 4) or invalid (HTML 4.01/XHTML 1.0 Strict)/obsolete (HTML 5) “language” attribute of the “script” element is the problem. >> <http://validator.w3.org/> >> >> >> Head shaking, > > How pompous can you be? You are projecting. <https://en.wikipedia.org/wiki/Dunning–Kruger_effect> -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-11-13 01:20 +0000 |
| Message-ID | <87h8tzug8m.fsf@bsb.me.uk> |
| In reply to | #34327 |
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: > Ben Bacarisse wrote: > >> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >> >> Are you counting the "..."? (I would not be surprised!) Otherwise I >> see only one. > > The dots are the obvious syntax errors, yes. As I said, I am not surprised. You probably say "yes" when asked if you want red or white at a party. >>> simply would not do what you think it does. >> >> How on Earth do you know that? > > In your favor, I have assumed reasonable thinking, but obviously I was > wrong. > >> Obviously I'm guessing a bit about what the OP wants, but it does what >> I want! > > Oh, really? And what would that be? Don't be silly. You know perfectly well. The mystery is why you thought you knew it was not doing what I wanted. >>> Also, the HTML is still invalid. >> >> Of course. What possible value could there be in my adding the missing >> title element to the OP's HTML? > > The missing “title” element is not the problem because this code needs to be > inserted in an HTML document that is supposed to have a “title” element > already; the missing “type” attribute (HTML 4) or invalid (HTML 4.01/XHTML > 1.0 Strict)/obsolete (HTML 5) “language” attribute of the “script” element > is the problem. You have an odd notion of invalid HTML. The language attribute does not make the document non-conforming unless there is also a type attribute. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-11-13 03:49 +0100 |
| Message-ID | <2906890.44csPzL39Z@PointedEars.de> |
| In reply to | #34328 |
Ben Bacarisse wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >> Ben Bacarisse wrote: >>> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >>> Are you counting the "..."? (I would not be surprised!) Otherwise I >>> see only one. >> The dots are the obvious syntax errors, yes. > > As I said, I am not surprised. You probably say "yes" when asked if you > want red or white at a party. Straw man. >>> Obviously I'm guessing a bit about what the OP wants, but it does what >>> I want! >> Oh, really? And what would that be? > > Don't be silly. You know perfectly well. The mystery is why you > thought you knew it was not doing what I wanted. Straw man again, also /ad hominem/ and shifting the burden of proof. You are full of fallacies today. >>>> Also, the HTML is still invalid. >>> >>> Of course. What possible value could there be in my adding the missing >>> title element to the OP's HTML? >> The missing “title” element is not the problem because this code needs to >> be inserted in an HTML document that is supposed to have a “title” >> element already; the missing “type” attribute (HTML 4) or invalid (HTML >> 4.01/XHTML 1.0 Strict)/obsolete (HTML 5) “language” attribute of the >> “script” element is the problem. > > You have an odd notion of invalid HTML. The language attribute does not > make the document non-conforming unless there is also a type attribute. Wrong; also, your code did not contain a “type” attribute and you did not specify the (X)HTML version, so, as they say, there’s that. -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-11-13 16:45 -0800 |
| Message-ID | <9ed21080-457e-4a82-a1a7-7f294269b0ab@googlegroups.com> |
| In reply to | #34328 |
On Monday, November 13, 2017 at 2:20:22 AM UTC+1, Ben Bacarisse wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: > > Ben Bacarisse wrote: > > > >> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: > >> > >> Are you counting the "..."? (I would not be surprised!) Otherwise I > >> see only one. > > > > The dots are the obvious syntax errors, yes. > > As I said, I am not surprised. You probably say "yes" when asked if you > want red or white at a party. He's a jerk, most of the objections are simply nonsense as far as one keeps in mind 1) that you have replied using the original code, which is just fine unless one does decide to get deeper, and 2) that you did say the code was just written as that, probably with errors in it. That said, your code is indeed and usually ugly (just as any beginner's code is, be reassured), though for more general reasons. One example, <script language=JavaScript> is indeed horrific, not just the use of the language attribute but even more (to my taste) the missing quotes around the value. Sure, it will validate re some or other standard, but that's indeed not the whole story... And you might now say "what the heck is actually wrong with that", and that's a legitimate question, that you will be able to answer yourself when you have at least written ten million lines of production code yourself (the number is from the top of my head, just take the figure of speech), and then e.g. you start getting proficient with "defensive coding", by which I mean how to prevents bugs from occurring at all: and with JS running on so many heterogeneous platforms, this is particularly important (but the same is with HTML). Not to mention the aesthetic side of things, which instead one can only appreciate after some 20 years of production level work (now this is quite precise), where aesthetics means you can finally and literally *feel* the thingy... Have fun, Julio
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web