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==â?
Need help with a Java script question.
- TigerRaptor
- DBB Fleet Admiral
- Posts: 2678
- Joined: Tue Feb 01, 2000 6:00 am
Is that all the code that's provided?
If so, it will be a lot easier if you look at the code formatted sanely:
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"
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");
}
}
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"
- TigerRaptor
- DBB Fleet Admiral
- Posts: 2678
- Joined: Tue Feb 01, 2000 6:00 am