JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
plz help with really simple task Posted by john2kay on 5 Apr 2006 at 11:19 PM
could any1 with suger on top help me with this really simple assignment, im a total newb i know, but cant figure this out.

" Display the days of the week (Monday, Tuesday, etc) starting with the rundate. Display them each in a different color, except Sunday is always red. "

like i would need the list of 7 days like a vertical but somehow code it so where the days starts with current day. so run date would have to be first.

so if today is say tuesday

tuesday
wednesday etc.
Report
Re: plz help with really simple task Posted by zibadian on 6 Apr 2006 at 4:49 AM
: could any1 with suger on top help me with this really simple assignment, im a total newb i know, but cant figure this out.
:
: " Display the days of the week (Monday, Tuesday, etc) starting with the rundate. Display them each in a different color, except Sunday is always red. "
:
: like i would need the list of 7 days like a vertical but somehow code it so where the days starts with current day. so run date would have to be first.
:
: so if today is say tuesday
:
: tuesday
: wednesday etc.
:
This might help: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_date_weekday
To set the color, simply write the appropriate HTML-tag(s) along with the date.
The best option is to use a while do loop to write the other dates, where the array is circular. In other words if the day-index is larger than 6 make it 0.
Report
Re: plz help with really simple task Posted by john2kay on 6 Apr 2006 at 9:43 AM
thanks for the input, but this only show 1 day i need all the days of week on same page strating from current, iknow how to do color thing,but how do i loop the days of week starting with today?
: This might help: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_date_weekday
: To set the color, simply write the appropriate HTML-tag(s) along with the date.
: The best option is to use a while do loop to write the other dates, where the array is circular. In other words if the day-index is larger than 6 make it 0.
:

Report
Re: plz help with really simple task Posted by john2kay on 6 Apr 2006 at 9:46 AM
This message was edited by john2kay at 2006-4-6 11:14:2

i think u may have suggested what i need with the circular loop strig but im not sure how to write that.
: The best option is to use a while do loop to write the other dates, where the array is circular. In other words if the day-index is larger than 6 make it 0.
:

basically what im am rying to figure out is once it have current date ie:

weekday[d.getDay()])
what is code for following weekday
and next
next
so on



Report
Re: plz help with really simple task Posted by zibadian on 6 Apr 2006 at 3:01 PM
: This message was edited by john2kay at 2006-4-6 11:14:2

: i think u may have suggested what i need with the circular loop strig but im not sure how to write that.
: : The best option is to use a while do loop to write the other dates, where the array is circular. In other words if the day-index is larger than 6 make it 0.
: :
:
: basically what im am rying to figure out is once it have current date ie:
:
: weekday[d.getDay()])
: what is code for following weekday
: and next
: next
: so on
:
:
:
Here is an example of a while-loop: http://www.w3schools.com/js/tryit.asp?filename=tryjs_while
This code can easily be modified to show all the dates.

Report
Re: plz help with really simple task Posted by john2kay on 6 Apr 2006 at 3:36 PM
i tried this and it didnt work, what am i doing wrong?

"<html>
<body>

<script type="text/javascript">

var d=new Date()
var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"
i = weekday[d.getDay()]
while (i <= 7)
{
document.write("The day is " + i)
document.write("<br>")
i++
}
</script>


</body>
</html>
"
Report
Re: plz help with really simple task Posted by zibadian on 6 Apr 2006 at 3:44 PM
: i tried this and it didnt work, what am i doing wrong?
:
: "<html>
: <body>
:
: <script type="text/javascript">
:
: var d=new Date()
: var weekday=new Array(7)
: weekday[0]="Sunday"
: weekday[1]="Monday"
: weekday[2]="Tuesday"
: weekday[3]="Wednesday"
: weekday[4]="Thursday"
: weekday[5]="Friday"
: weekday[6]="Saturday"
: i = weekday[d.getDay()]
: while (i <= 7)
: {
: document.write("The day is " + i)
: document.write("")
: i++
: }
: </script>
:
:
: </body>
: </html>
: "
:
The variable i should be an integer, which points to the current day:
  i = d.getDay();
  while (i <= 7 )
  {
    document.write("The day is " + weekday[i])
    i++
  }

This will show all the days from today till saturday. By checking if i is different from d.getDay(), and setting i back to 0 if it becomes 7, you can also show the weekdays before today.
Report
Re: plz help with really simple task Posted by john2kay on 6 Apr 2006 at 3:59 PM
This message was edited by john2kay at 2006-4-6 15:59:52

ok i fied it up but now i get 1 line saying day i undefined???

"<html>
<body>

<script type="text/javascript">

var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
i = weekday[d.getDay()];
while (i <= 7);
{
document.write("The day is " + weekday[i])

};
</script>


</body>
</html>
"

thx in advamce
Report
Re: plz help with really simple task Posted by john2kay on 6 Apr 2006 at 5:25 PM
ok i worked for a long time and i am at this point, only problem is colors are not as i defined them, red is supposed to be only red color.

"<html><title>Marks JS</title>
<body> <font size = "4">
<script language = "JavaScript">
<!--Hide from non-Javascript browsers
var Today = new Date() ;
var DayNumber = Today.getDay() ;

var Day;
var weekday=new Array(14);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
weekday[7]="Sunday";
weekday[8]="Monday";
weekday[9]="Tuesday";
weekday[10]="Wednesday";
weekday[11]="Thursday";
weekday[12]="Friday";
weekday[13]="Saturday";
var color=new Array(14);
color[0]="red";
color[1]="blue";
color[2]="green";
color[3]="orange";
color[4]="black";
color[5]="yellow";
color[6]="gray";
color[7]="red";
color[8]="Monday";
color[9]="blue";
color[10]="green";
color[11]="orange";
color[12]="black";
color[13]="yellow";
i = Today.getDay();
for(i=0;i<7;i++)
{
DayNumber = Today.getDay() +i;
document.write("<font color = " + color[i] + " >"+"The day is " + weekday[DayNumber] + "<br/></font>") ;
}

//Stop hiding -->
</script></font></table></body></html>"
Report
Re: plz help with really simple task Posted by zibadian on 6 Apr 2006 at 10:13 PM
: ok i worked for a long time and i am at this point, only problem is colors are not as i defined them, red is supposed to be only red color.
:
: "<html><title>Marks JS</title>
: <body> <font size = "4">
: <script language = "JavaScript">
: <!--Hide from non-Javascript browsers
: var Today = new Date() ;
: var DayNumber = Today.getDay() ;
:
: var Day;
: var weekday=new Array(14);
: weekday[0]="Sunday";
: weekday[1]="Monday";
: weekday[2]="Tuesday";
: weekday[3]="Wednesday";
: weekday[4]="Thursday";
: weekday[5]="Friday";
: weekday[6]="Saturday";
: weekday[7]="Sunday";
: weekday[8]="Monday";
: weekday[9]="Tuesday";
: weekday[10]="Wednesday";
: weekday[11]="Thursday";
: weekday[12]="Friday";
: weekday[13]="Saturday";
: var color=new Array(14);
: color[0]="red";
: color[1]="blue";
: color[2]="green";
: color[3]="orange";
: color[4]="black";
: color[5]="yellow";
: color[6]="gray";
: color[7]="red";
: color[8]="Monday";
: color[9]="blue";
: color[10]="green";
: color[11]="orange";
: color[12]="black";
: color[13]="yellow";
: i = Today.getDay();
: for(i=0;i<7;i++)
: {
: DayNumber = Today.getDay() +i;
: document.write("<font color = " + color[i] + " >"+"The day is " + weekday[DayNumber] + "<br/></font>") ;
: }
:
: //Stop hiding -->
: </script></font></table></body></html>"
:
It looks fine to me. I see each color only once, starting with red.
Here's how I would have coded it:
  i = Today.getDay();
  document.write("<font color = " + color[i] + " >"+"Today is " + weekday[i] + "<br/></font>") ;
  i++;
  while (i <> Today.getDay())
  {
    document.write("<font color = " + color[i] + " >"+"The day is " + weekday[i] + "<br/></font>") ;
    i++
    if (i == 7) 
      i = 0;
  }

If you use this code, the arrays don't need to be "doubled", becasue i never gets above 6.
Report
Re: plz help with really simple task Posted by john2kay on 7 Apr 2006 at 2:46 PM
"It looks fine to me. I see each color only once, starting with red.
Here's how I would have coded it"

thats the problem, its not supposed to start with red unless today is sunday, red should only appear once and only be for sunday.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.