Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 20th, 2005, 10:24 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie Help!

Quote:
quote:Write a JavaScript program that checks the system time and then
based on the following rules: -
If the time is after 12:00am (midnight) but before 12:00 pm (noon)
loop to display the numbers from 1 to 10 in a list down the page.
should be white and the font size 16 point, and the background navy.
If the time is after 12:00pm (noon) but before 12:00am (midnight)
display the numbers from 20 to 30 in a list across the page. The digits
be yellow and the font size 14 point, and the background navy.
Code:
h1 { 
    font-size: 16px;
    color:#FFFFFF;
    background-color:#000066
   }

h2 { 
    font-size: 14px;
    color: #FFFF00;
    background-color:#000066
    }

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Time</title>
<link rel="stylesheet" href="time.css" type="text/css" />
</head>
<body>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Time</title>
<link rel="stylesheet" href="time.css" type="text/css" />
<script type="text/JavaScript">
//<![CDATA[
var d = new Date()
while (d.getHours <= "0"   && < "12")
{
document.write("<h1>1</h1><br />");
document.write("<h1>2</h1><br />");
document.write("<h1>3</h1><br />");
document.write("<h1>4</h1><br />");
document.write("<h1>5</h1><br />");
document.write("<h1>6</h1><br />");
document.write("<h1>7</h1><br />");
document.write("<h1>8</h1><br />");
document.write("<h1>9</h1><br />");
document.write("<h1>10</h1>");
}

for ()
{
document.write("<h2>20 </h2>");
document.write("<h2>21 </h2>");
document.write("<h2>22 </h2>");
document.write("<h2>23 </h2>");
document.write("<h2>24 </h2>");
document.write("<h2>25 </h2>");
document.write("<h2>26 </h2>");
document.write("<h2>27 </h2>");
document.write("<h2>28 </h2>");
document.write("<h2>29 </h2>");
document.write("<h2>30 </h2>");
}
//]]>
</script>
</head>
<body>
</body>
</html>
</body>
</html>
Am i on the right track?

  #2 (permalink)  
Old March 21st, 2005, 03:42 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Please give your posts sensible titles ("My Homework" perhaps :)).
You have the basics but I would suggest the following:
 
  • I'm sure they are expecting you to use a "for loop" to write the numbers.
  • The result of d.getHours() is a number not a string so compare with 0 not "0" etc, string comparisons work differently.
  • Store the results of the call to getHours(). If the hour changes during loading your results will look strange. Unlikely but possible.
  • You don't need a while loop. Just check whether the hour falls into one category and if so run your for loop for 1 to 10, otherwise run the for loop for 20 to 30.


--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help the newbie!! shelly.aix Visual Basic 2008 Essentials 2 December 16th, 2008 07:35 AM
Newbie help... mkruger XSLT 7 October 24th, 2007 02:33 AM
Newbie here jmac731976 HTML Code Clinic 13 August 29th, 2007 03:54 PM
Newbie please help indyanguy XSLT 1 September 2nd, 2005 09:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.