Need help with a Java script question.

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
TigerRaptor
DBB Fleet Admiral
DBB Fleet Admiral
Posts: 2582
Joined: Tue Feb 01, 2000 6:00 am

Need help with a Java script question.

Post by TigerRaptor »

I've decided to take a Java Script course online, and for while I've had no trouble learning the codes and answering the question. But I don't seem to understand the answer to this question. Maybe I'm over analyzing it to much. Please help me out.


As written in the book.

What does the following script do?


If(Day==â?
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

Is that all the code that's provided?

If so, it will be a lot easier if you look at the code formatted sanely:

Code: Select all

if(Day == "Friday")
{
  document.write("T.G.I.F!");
}
else
{
  if(Day == "Monday")
  {
    document.write("Another Manic Monday!");
  }
  else
  {
    document.write("Good morning");
  }
}
You need to understand if statements.

if(expression)
{
// the code inside this block is executed
// if expression evaluates to true.
}
else
{
// the code inside this block is executed
// if expression evaluates to false.
}

So that code snippet works as follows.

Is the variable Day equivalent to the string expression "Friday"?
- If so, then call the write method on the document object with the argument "T.G.I.F."
- If not, then do the following:
-- Is the variable Day equivalent to the string expression "Monday"?
--- If so, then call the write method on the document object with the argument "Another Manic Monday!"
--- If not, then call the write method on the document object with the argument "Good morning"
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6458
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

can javascript access the header request for a page?
User avatar
Instig8
DBB Ace
DBB Ace
Posts: 347
Joined: Wed Jun 20, 2001 2:01 am
Location: Orange County, CA, USA
Contact:

Post by Instig8 »

throws exception cause 'Day' is not defined.
User avatar
TigerRaptor
DBB Fleet Admiral
DBB Fleet Admiral
Posts: 2582
Joined: Tue Feb 01, 2000 6:00 am

Post by TigerRaptor »

Sorry for the late reply. But this backwards JavaScript bull★■◆● is drives me up the wall sometimes. All right I think I understand how this works now. Iâ??m going to say the answer is number 1 only because the others donâ??t seem to add up with what youâ??re saying. Thanks for the help.
Post Reply