English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Copy the example snippet of code & get it to run. Then modify the code so it
includes the message "Good Evening". Another IF statement should do the trick
however there are several other ways to do the same thing, You may make multiple
versions of the program.



<br /> </head><br /> <body><br /> <p><br /> If the time on your browser is less than 10, <br> you get a "Good Morning" greeting. <br><br /> Otherwise you will get a "Good day" greeting.<br /> </p><br /> <br /> <script type="text/javascript"><br /> var d = new Date()<br /> var time = d.getHours()<br /> <br /> if (time < 10)<br /> {<br /> document.write("<b>Good morning</b>")<br /> }<br /> else<br /> {document.write("<b>Good day</b>")<br /> }<br /> </script><br /> <br /> <p<HR><br /> This example demonstrates the If...else statement.<br /> </p><br /> <br /> </body> </p> <p> <small> <a href="/en/2007-12-06">2007-12-06</a> <span>01:51:58</span> · <span>5 answers</span> · asked by <u>:Phil</u> <b>5</b> in <span><a href="/en/category/computers-and-internet">Computers & Internet</a></span> <span> ➔ </span> <span><a href="/en/category/computers-and-internet/programming-and-design">Programming & Design</a></span> </small> </p> </div> </div> <h3 style="background:#fff;border-bottom:3px solid green;">5 answers</h3> <div style='margin:6px 0px;'> <div id="answer20071206024926" class='answer answer_best' > <!-- <b>Answer #1</b> --> <p class='answer-content' lang="en"> Above solutions won't work if hour is one of the ranges <br /> <br /> for ex. if time is 4:20 AM variable t will have value of '4' and none of conditions would satisfy the value so it would end prinitng wrong description to suffice that<br /> <br /> condition actually should be (time >= 4 && time < 10)<br /> <br /> <script type="text/javascript"><br /> var d = new Date()<br /> var time = d.getHours()<br /> if(time >= 20 && time < 4) <br /> {<br /> // between 8:00 PM and 4:00 PM<br /> document.write("<b>Good morning</b>"); <br /> }<br /> else if(time >=4 && time <10)<br /> {<br /> // between 4:00 AM and 12:00 Noon<br /> document.write("<b>Good Morning</b>");<br /> }<br /> else if(time >=12 && time < 16)<br /> {<br /> // between 12:00 Noon and 4:00 PM<br /> document.write("<b>Good Afternoon</b>");<br /> }<br /> else if(time >= 16 && time < 20)<br /> {<br /> // between 4:00 PM and 8:00 PM<br /> document.write("<b>Good Evening</b>");<br /> }<br /> else<br /> {<br /> // All other hours.. between 10:00 AM and 12:00 Noon<br /> document.write("<b>Good Day</b>");<br /> }<br /> </script> </p> <p> <small> 2007-12-06 02:49:26 · <a href="#answer20071206024926">answer #1</a> · <span>answered by <u>Man D.</u> <b>2</b></span> · <span>1<span style='color:green;'>⤊</span></span> <span>0<span style='color:red;'>⤋</span></span> </small> </p> </div> <div id="answer20160407212914" class='answer' > <!-- <b>Answer #2</b> --> <p class='answer-content' lang="en"> Spiritually speaking, it's so we can ask a question that might be on shaky ground as far as Y!A and the report monkeys are concerned. It seems silly, but it usually works. And there are some people who still care about violation notices. I think most of us figure that any given account is on borrowed time if you participate in this Forum often, but there are those who just don't like getting VN's. </p> <p> <small> 2016-04-07 21:29:14 · <a href="#answer20160407212914">answer #2</a> · <span>answered by <u>Anonymous</u></span> · <span>0<span style='color:green;'>⤊</span></span> <span>0<span style='color:red;'>⤋</span></span> </small> </p> </div> <div id="answer20071206020436" class='answer' > <!-- <b>Answer #3</b> --> <p class='answer-content' lang="en"> <script type="text/javascript"><br /> var d = new Date()<br /> var time = d.getHours()<br /> <br /> if (time < 10)<br /> {<br /> document.write("<b>Good morning</b>")<br /> }<br /> <br /> else if (time > 10 && time < 23)<br /> {<br /> document.write("<b>Good Evening</b>")<br /> }<br /> else<br /> {document.write("<b>Good day</b>")<br /> }<br /> </script> </p> <p> <small> 2007-12-06 02:04:36 · <a href="#answer20071206020436">answer #3</a> · <span>answered by <u>nado</u> <b>2</b></span> · <span>1<span style='color:green;'>⤊</span></span> <span>0<span style='color:red;'>⤋</span></span> </small> </p> </div> <div id="answer20071206020318" class='answer' > <!-- <b>Answer #4</b> --> <p class='answer-content' lang="en"> if (time < 10 && time>4)<br /> {<br /> document.write("<b>Good morning</b>")<br /> }<br /> elseif( time > 16 && time < 20 )<br /> {<br /> document.write("<b>Good evening</b>")<br /> }elseif( time >= 20 && time < =4 )<br /> document.write("<b>Good night</b>")<br /> else{<br /> document.write("<b>Good day</b>")<br /> } </p> <p> <small> 2007-12-06 02:03:18 · <a href="#answer20071206020318">answer #4</a> · <span>answered by <u>kaveh</u> <b>3</b></span> · <span>1<span style='color:green;'>⤊</span></span> <span>0<span style='color:red;'>⤋</span></span> </small> </p> </div> <div id="answer20071206015835" class='answer' > <!-- <b>Answer #5</b> --> <p class='answer-content' lang="en"> How do you expect to learn if you don't do your own homework? </p> <p> <small> 2007-12-06 01:58:35 · <a href="#answer20071206015835">answer #5</a> · <span>answered by <u>Anonymous</u></span> · <span>1<span style='color:green;'>⤊</span></span> <span>1<span style='color:red;'>⤋</span></span> </small> </p> </div> </div> </article> </section> <div style="background:#888;padding:8px;margin-top:16px;"> fedest.com, questions and answers </div> </body> </html>