can some1 help with my kink is java

M

mark2kay

the assignment was to make list of 7 days starting with curent only
that red was supposed to be in red. ive creted code only problem is its
automatically makes 1st day red, which would be ok if day is sunday but
6 days out of week assignment will be wrong, heres code.

"<html><title>Marks JS</title>

<body> <font size = "4">

<script language = "JavaScript">

<!--Hide from non-Javascript browsers

var Today = new Date() ;

var DayNumber = Today.getDay() ;



var Day;

var weekday=new Array(14);

weekday[0]="Sunday";

weekday[1]="Monday";

weekday[2]="Tuesday";

weekday[3]="Wednesday";

weekday[4]="Thursday";

weekday[5]="Friday";

weekday[6]="Saturday";

weekday[7]="Sunday";

weekday[8]="Monday";

weekday[9]="Tuesday";

weekday[10]="Wednesday";

weekday[11]="Thursday";

weekday[12]="Friday";

weekday[13]="Saturday";

var color=new Array(14);

color[0]="red";

color[1]="blue";

color[2]="green";

color[3]="orange";

color[4]="black";

color[5]="yellow";

color[6]="gray";

color[7]="red";

color[8]="Monday";

color[9]="blue";

color[10]="green";

color[11]="orange";

color[12]="black";

color[13]="yellow";

i = Today.getDay();

for(i=0;i<7;i++)

{

DayNumber = Today.getDay() +i;

document.write("<font color = " + color + " >"+"The day is " +
weekday[DayNumber] + "<br/></font>") ;

}



//Stop hiding -->

</script></font></table></body></html>"
 
H

Hal Rosser

the assignment was to make list of 7 days starting with curent only
that red was supposed to be in red. ive creted code only problem is its
automatically makes 1st day red, which would be ok if day is sunday but
6 days out of week assignment will be wrong, heres code.

**snip**
document.write("<font color = " + color + " >"+"The day is " +
weekday[DayNumber] + "<br/></font>") ;

in your code listed above, if you change the first line to:
document.write("<font color = " + color[DayNumber] + " >"+"The day is " +
(Adding an index in square braces after the array variable named color)
Your output will (probably) do what you are expecting.
You have other errors and some deprecated tags and attributes, but that
little change will make it work.
 
Q

qualify19

omg, you are teh greatest it worked, i tested by changing my schedule.

thx.

i have a html job i need done you got time/intrested? im paying
 
H

Hal Rosser

omg, you are teh greatest it worked, i tested by changing my schedule.

thx.

i have a html job i need done you got time/intrested? im paying

But I am not the greatest -( yet). I'll be a student for the next 20 years.
I wish I was a teenager again - that's when I knew everything.
and no, but thanks - about the job.
IMO, the most helpful of posters on this group are Richard Cornford and one
called RobG.

Good luck on your studies. And if you do your own work, you'll learn more.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Sun, 9 Apr 2006 14:47:20 remote, seen in (e-mail address removed) posted :
the assignment was to make list of 7 days starting with curent only
that red was supposed to be in red. ive creted code only problem is its
automatically makes 1st day red, which would be ok if day is sunday but
6 days out of week assignment will be wrong, heres code.

But red is always red. Your specification is unclear. Your subject line
is meaningless.

for ( D = new Date(), k = -7 ; k++ ; D.setDate(D.getDate()+1) )
document.writeln(D.toString().fontcolor(D.getDay()?"blue":"red"), "<br>")

No doubt if you had been paying attention to your class instruction you
would have been able to do the job in more or less the manner that you
attempted. I've therefore done it in a manner which might, by making you
think, teach you an equivalent amount. Don't expect your instructor to
accept it as your own work.
 
H

Hal Rosser

Dr John Stockton said:
JRS: In article <[email protected]>
, dated Sun, 9 Apr 2006 14:47:20 remote, seen in
for ( D = new Date(), k = -7 ; k++ ; D.setDate(D.getDate()+1) )
document.writeln(D.toString().fontcolor(D.getDay()?"blue":"red"),
"<br>")

Some professors would beat you about the head and shoulders for using a
post-increment operator as a boolean test, and for placing (code that should
be in the body of the loop) as the "update-Expression" in the top parens of
the loop, or for using a day number as a boolean test. I'm beginning to see
what they mean about your code. my GOD, man! Have you no shame? hehehe ;-)
You ride the rugged edge of the language specifications (but inside the
bounds ).
Is it no longer "fashionable" to try to conform (as much as practical) to
XHTML practices - like using "<br />" ?
 
L

Lee

Hal Rosser said:
"<br>")

Some professors would beat you about the head and shoulders for using a
post-increment operator as a boolean test, and for placing (code that should
be in the body of the loop) as the "update-Expression" in the top parens of
the loop, or for using a day number as a boolean test.

All completely ridiculous things to be bothered by.
But then, a surprising number of professional "developers" that
I run into these days have a really hard time understanding code.
I'm beginning to see
what they mean about your code. my GOD, man! Have you no shame? hehehe ;-)

The code you're complaining about is essentially "library code".
Efficiency is a higher priority than readability or even
maintainability. It is not intended to be read and understood
by the typical user.


--
 
H

Hal Rosser

Lee said:
Hal Rosser said:

All completely ridiculous things to be bothered by.
But then, a surprising number of professional "developers" that
I run into these days have a really hard time understanding code.
;-)

The code you're complaining about is essentially "library code".
Efficiency is a higher priority than readability or even
maintainability. It is not intended to be read and understood
by the typical user.

I'm not *complaining* about the code (in this post) - just making some
'jovial' comments.
The posted code is, as you say, efficient and not intended to be read and
understood by the typical user.
Well - there you go! You said it. Does it also follow that this newsgroup is
not intended to be read and understood by the typical user?
:;-)
Hal
 
L

Lee

Hal Rosser said:
I'm not *complaining* about the code (in this post) - just making some
'jovial' comments.
The posted code is, as you say, efficient and not intended to be read and
understood by the typical user.
Well - there you go! You said it. Does it also follow that this newsgroup is
not intended to be read and understood by the typical user?

No, but when somebody asks how to round off, one valid answer is to
point them to a function that does what they want, even if they may
not be expected to understand how it does it.

If they ask how to do something of a more general nature, it might
be better to respond with code that sacrifices efficiency for the
sake of accessibility.


--
 
R

Richard Cornford

The posted code is, as you say, efficient and not intended
to be read and understood by the typical user.
Well - there you go! You said it. Does it also follow that
this newsgroup is not intended to be read and understood
by the typical user? :;-)

It is probably a personal thing but I prefer the 'user' to be thought of
as the person who ends up interacting with the software written, and the
person 'using' the language as the programmer. In which case this group
is definitely not for the typical user (as they couldn't (even
shouldn't) care less about javascript, and probably don't even know what
it is).

But would the implication of what you are saying be that all posted code
should be suitable for novice javascript programmers? That would not be
such a good idea as then the group would never be able to assist people
in getting beyond the novice stage. In reality the code posted to the
group ranges from that suited to beginners to some of the most advanced
javascript written, as it should as that way the group can be
interesting/instructive even for its more long standing contributors.

Ultimately, if someone does not understand some posted code they can
always have a go at formulating a question about it and posting that to
the group in the hope of an explanation. There are people willing to
have a go at explaining code if suitably asked.

Richard.
 
R

Richard Cornford

Hal said:
Dr John Stockton wrote:

Some professors would beat you about the head and shoulders
for using a post-increment operator as a boolean test, and
for placing (code that should be in the body of the loop)
as the "update-Expression" in the top parens of the loop,
or for using a day number as a boolean test.

In loosely-types javascript all values have implicit trueness so it is
not at all unusual to see values that are known not to be of boolean
type in contexts where other languages would require boolean values.
That is also not undesirable as working with a loosely-typed language
places the onus on the programmer to keep track of the types of values
and appreciate the consequences and implications of any implicit
type-conversion.

This wider concept of trueness, extending beyond the Boolean type, is
evident in the language itself, where, for example, the logical AND and
OR operators do not necessarily result in boolean values, instead the
actual value of the pertinent operand is the result.

So a javascript programmer should be expected to able to see a value in
a context where it would be subject to the application of the internal
ToBoolean function and understand what the possible resulting boolean
values will be. That is just part of the discipline of writing with a
loosely typed language.
I'm beginning to see what they mean about your code. my GOD,
man! Have you no shame? hehehe ;-) You ride the rugged edge
of the language specifications (but inside the bounds ).

The terseness of John's code is if occasionally commented upon, but that
is nowhere near the 'ragged edge' of ECMAScript.
Is it no longer "fashionable" to try to conform (as much as
practical) to XHTML practices - like using "<br />" ?

It is a lamentable truth that the average standard of technical
understanding possessed by web developers/designers world-wide is
atrocious. If something becomes 'fashionable' the odds are good that it
did not become fashionable for sound technical reasons.

HTML and XHTML are distinct mark-up languages, and in our context of
browser scripting that distinction is manifest in these two different
mark-up languages resulting in two distinct types of DOM being exposed
to be scripted. And the differences between those two types of DOM (by
specification and in practice) are such that very few non-trivial
scripts will be capable of successfully interacting with both types of
DOM. We have the HTML DOM, with its case insensitivity, historical
shortcut features, preference for setting Element properties directly,
and so on. While the XHTML DOM is case sensitive, rarely implements more
than is explicitly specified, prefers to have Elements defined with the
setAttribute (or setAttributeNS) methods, has an interest in namespaces,
and traditionally omit some features commonly used in HTML DOMs such
as - document.write -. If a document is to be scripted it is quite
important to know which type of DOM is being scripted, and advice on
scripting one DOM is likely to get in the way when scripting the other.

The decision as to which type of DOM a browser creates is based entirely
upon the content-type header sent by the server with the document. If
the content-type is text/html then the browser will interpret the
document as HTML and build an HTML DOM. Only when a browser supports
XHTML, receives as well-formed XHTML document and receives a formally
correct XHTML mime type in the content-type header is an XHTML DOM
created, and those are also the only circumstances under which a
document really is XHTML, regardless of the appearance of its mark-up.

Because IE does not support XHTML, and cannot create an XHTML DOM, in
order for a document that had XHTML-like mark-up to be displayed in IE
it must be sent with a text/html content-type header. IE then interprets
that document as HTML and error-corrects all of the XTHML-like mark-up
back into tag soup HTML. That is, serving documents that superficially
resemble XHTML to be displayed by IE imposes an entire extra
error-correction stage on the client for the document to be interpreted
as the HTML that it would have been without the imposing the illusion of
document. With the additional irony that sending this document in this
way to a browser that does understand XHTML, like Mozilla or Opera, will
still result in its being interpreted as HTML, subject to
error-correction, and an HTML DOM being built for it.

All of this error-correction has implications for the resulting HTML DOM
as error-correction rules are not formally specified and browsers are
observed to behave differently while carrying it out, producing
structurally different HTML DOMs to be scripted.

Finally, there is the formal definition of HTML to be contended with. By
specification - <br / - is a shorthand for - <br></br> - in HTML, and
so - <br /> - is equivalent to - <br>&gt; -; a BR element followed by a
'greater than' symbol. Fortunately for the people following this
'fashion' most browsers do not follow this particualr formal rule and
instead regard it as an error to be corrected in HTML mark-up, though
there is always a chance that there are browsers that take the HTML
specification at its word and there the result will undesirable.

So it is not a question of what may or may not be fashionable. The
technically informed will write HTML mark-up when they want to serve a
document as text/html and script and HTML DOM, and XHTML mark-up when
they want to serve a document as XHTML and script an XHTML DOM. And with
IE not supporting the second option at all the former is the sensible
option when authoring in a commercial context. (The only alternative
being content negotiation, but you cannot content negotiate scripts and
attempting to write scripts that will work with XHTML DOMs and HTML DOMs
is double the effort for no tangible benefits, so not a sensible option
in a commercial context.)

Richard.
 
R

Richard Cornford

Richard Cornford wrote:
... without the imposing the illusion of document. ...
<snip>

Should have been: " without the imposing the illusion of XHTML on the
document"

Richard.
 
R

RobG

Hal Rosser said on 12/04/2006 7:05 AM AEST:
I'm not *complaining* about the code (in this post) - just making some
'jovial' comments.
The posted code is, as you say, efficient and not intended to be read and
understood by the typical user.
Well - there you go! You said it. Does it also follow that this newsgroup is
not intended to be read and understood by the typical user?

I does seem a bit contradictory to have an FAQ to answer what are likely
novice questions, and also to have posted in the same page code that is
expected to be used as-is and without regard for comprehension by those
very same novices. However, expanding the code with full comments and
descriptive variable names would likely quadruple its size (or more).

JRS may have a good point that post such code will encourage programmers
to learn how it works, and in learning that way more knowledge will
stick. But on the other hand it will frustrate some who feel it is
unnecessarily cryptic and as a result may turn to DynamicDrive or JSGuru
or other junk sites.

Richards advice is good - try to understand it, and if you have
questions about a specific point, ask here. Those who have made the
effort to understand before asking a question are treated much more
kindly than those who clearly haven't. :)
 
H

Hal Rosser

Lee said:
No, but when somebody asks how to round off, one valid answer is to
point them to a function that does what they want, even if they may
not be expected to understand how it does it.
*** ** That was a different thread ** does not apply here The OP in this
thread left off the array index - and a few other mistakes, but rounding was
not mentioned - (you can blast me on the other thread - and explain FAQ 4.6
to the group)
****
If they ask how to do something of a more general nature, it might
be better to respond with code that sacrifices efficiency for the
sake of accessibility.
***** yay! ** that's been my point on other posts (re: FAQ 4.6)
********** :)
Hal
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue,
11 Apr 2006 23:46:20 remote, seen in RobG
I does seem a bit contradictory to have an FAQ to answer what are likely
novice questions, and also to have posted in the same page code that is
expected to be used as-is and without regard for comprehension by those
very same novices. However, expanding the code with full comments and
descriptive variable names would likely quadruple its size (or more).

A FAQ, regularly posted to News, is not meant to be a tutorial; a
tutorial might be posted once, in suitably-sized pieces, to News for
comment, but should not be posted regularly. The heading of FAQ 4.6 is
a question, and the code answers it.

Those who want to understand code such as in 4.6 can always execute it
with pencil and paper. Or they could follow the link provided and see a
newer version embedded in more text.

<FAQENTRY>
Richard, for the next FAQ version, please look at my Web page section
js-round.htm#GC - the present version (which may change ...) has a StrU
with the same algorithm somewhat differently expressed. I provide both
PrfxTo and SpcsTo because I need PrfxTo there and elsewhere, and several
SpcsTo elsewhere - but, for StrU alone, SpcsTo(,) could be replaced with
PrfxTo(,," ").

M & N can in fact each be zero, though then giving a non-preferred
format. Negative is just silly; but, as they'll generally be supplied
as literals, it's generally not worth coding a check.
</FAQENTRY>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top