Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: simple question

38 views
Skip to first unread message

Ben Bacarisse

unread,
Nov 12, 2017, 9:22:50 AM11/12/17
to
super70s <supe...@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.

Thomas 'PointedEars' Lahn

unread,
Nov 12, 2017, 12:33:44 PM11/12/17
to
Ben Bacarisse wrote:

> super70s <supe...@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.

Ben Bacarisse

unread,
Nov 12, 2017, 3:28:35 PM11/12/17
to
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.

Thomas 'PointedEars' Lahn

unread,
Nov 12, 2017, 4:39:48 PM11/12/17
to
Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <Point...@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>

Ben Bacarisse

unread,
Nov 12, 2017, 8:20:22 PM11/12/17
to
Thomas 'PointedEars' Lahn <Point...@web.de> writes:

> Ben Bacarisse wrote:
>
>> Thomas 'PointedEars' Lahn <Point...@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.

Andrew Poulos

unread,
Nov 12, 2017, 9:26:51 PM11/12/17
to
On 13/11/2017 8:11 AM, super70s wrote:
> In article <87shdju...@bsb.me.uk>, Ben Bacarisse
> 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

Thomas 'PointedEars' Lahn

unread,
Nov 12, 2017, 9:49:26 PM11/12/17
to
Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <Point...@web.de> writes:
>> Ben Bacarisse wrote:
>>> Thomas 'PointedEars' Lahn <Point...@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.

Julio Di Egidio

unread,
Nov 13, 2017, 7:45:27 PM11/13/17
to
On Monday, November 13, 2017 at 2:20:22 AM UTC+1, Ben Bacarisse wrote:
> Thomas 'PointedEars' Lahn <Point...@web.de> writes:
> > Ben Bacarisse wrote:
> >
> >> Thomas 'PointedEars' Lahn <Point...@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
0 new messages