Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

plz help with really simple task

john2kayjohn2kay Posts: 10Member
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.

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • john2kayjohn2kay Posts: 10Member
    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.
    :

  • john2kayjohn2kay Posts: 10Member
    [b][red]This message was edited by john2kay at 2006-4-6 11:14:2[/red][/b][hr]
    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



  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by john2kay at 2006-4-6 11:14:2[/red][/b][hr]
    : 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.

  • john2kayjohn2kay Posts: 10Member
    i tried this and it didnt work, what am i doing wrong?

    "




    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++
    }





    "
  • zibadianzibadian Posts: 6,349Member
    : i tried this and it didnt work, what am i doing wrong?
    :
    : "
    :
    :
    :
    :
    : 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>
    :
    :
    :
    :
    : "
    :
    The variable i should be an integer, which points to the current day:
    [code]
    i = d.getDay();
    while (i <= 7 )
    {
    document.write("The day is " + weekday[i])
    i++
    }
    [/code]
    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.
  • john2kayjohn2kay Posts: 10Member
    [b][red]This message was edited by john2kay at 2006-4-6 15:59:52[/red][/b][hr]
    ok i fied it up but now i get 1 line saying day i undefined???

    "




    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




    "

    thx in advamce
  • john2kayjohn2kay Posts: 10Member
    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.

    "Marks JS



    "
  • zibadianzibadian Posts: 6,349Member
    : 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.
    :
    : "Marks JS
    :
    :
    :
    :
    "
    :
    It looks fine to me. I see each color only once, starting with red.
    Here's how I would have coded it:
    [code]
    i = Today.getDay();
    document.write(""+"Today is " + weekday[i] + "
    ") ;
    i++;
    while (i <> Today.getDay())
    {
    document.write(""+"The day is " + weekday[i] + "
    ") ;
    i++
    if (i == 7)
    i = 0;
    }
    [/code]
    If you use this code, the arrays don't need to be "doubled", becasue i never gets above 6.
  • john2kayjohn2kay Posts: 10Member
    "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.
Sign In or Register to comment.