Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Omar Elfishawi
Omar Elfishawi
4,060 Points

Showing a page a day

hi, thanks in advance for your help. I would like to build a fitness website where the customer gets access to a new, different workout every day. The fitness course will run every month for 30 days, so you have 30 pages for 30 different workout. The customer will receive everyday a link to the daily workout (day 1, day2, day3 etc up to 30, the final day) I would like each page to be visible only on its day (ex. if I start the plan the 1st january, on 1st january users can see only page 1, 2nd January page 2 will appear, then page 3 and so on...) How can I achieve that?

Is this an android question or html/JavaScript or something else?

5 Answers

I am not completely understanding the use-case but from what i understand is, you need to show the current and previous date content.

for views(html): use a property: Visibility.[provide 31 ids for each day][initially all being false]

In scripts:

Get current date;
for each element check:
     if current date matches certain criteria 
     then associated element_id.visibility = true [or false as per the need]

Do comment if its not clear and want to discuss more.

Omar Elfishawi
Omar Elfishawi
4,060 Points

Hi Krishna, thanks for your help. I am just getting started so though I understand the logic you suggested me (beautiful!) I doubt I can implement this. If you could share with me some learning tools that can help me get close to this I would be very grateful! ciao

I wrote a detailed answer but the treehouse site failed and its not something new if you had been here for a while. It sucks, and it sucks even more when you report it multiple times and it still doesn't improves. :(

So i am going to share a few links: https://stackoverflow.com/questions/26813808/showing-html-in-javascript-and-loop-control https://stackoverflow.com/questions/4313382/using-javascript-jquery-to-show-certain-elements-on-certain-dates https://stackoverflow.com/questions/13121448/show-hide-divs-based-on-date https://www.w3schools.com/howto/howto_css_calendar.asp

So first create a html page for one day and do provide tag/id/name/class as per need because they'll be helpful for using javascript.

In terms of script: on page load, check if current date matches with the data being displayed, if not hide and make visible as per the need.

This is not a code but a level-0 view of what its going to look like...
VIEW[html]

Create a template
e.g. <div id="Day-1" class="itemReps" style="Visibility:False">
        <div>
            <p></p>
            <ul>
                <li>Do something</li>
                <li>DO other things</li>
                <li>...</li>
                <li>...</li>
                <li>...</li>
            </ul>
        </div>
        <div>
        </div>
        or anyther elements you want to display
    </div>

Script:
js.load()//to run on page load
{
    curr_date = get current date
    //get.ElementsbyClassName("itemReps);
    var elementCollection = new Array();
    var allElements = document.getElementsByTagName("*");
    for(i = 0; i < allElements.length; i++){
        if(allElements[i].id == "Day-"+curr_date)
            elementCollection.push(allElements[i]);

    }
    do something for everything in elementCollection[like element.property(visibility)=True;
}
Omar Elfishawi
Omar Elfishawi
4,060 Points

Thanks Krishna! I really appreciate the time and effort you put in helping me! Ill be studying, working on it and keep you update it! Cheers man!!