Page 1 of 1

Need help with a Java script question.

Posted: Wed Nov 16, 2005 3:59 pm
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==â?

Posted: Wed Nov 16, 2005 9:59 pm
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"

Posted: Thu Nov 17, 2005 1:03 am
by fliptw
can javascript access the header request for a page?

Posted: Thu Nov 17, 2005 10:12 pm
by Instig8
throws exception cause 'Day' is not defined.

Posted: Thu Nov 17, 2005 10:23 pm
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.