html - Display separate text strings each day -
i want display text string, or bit of code each day of week 2 weeks, repeat. through days display monday 1, tuesday 1...friday 1, monday 2, tuesday 2...friday 2. revert monday 1. if there way without using i-frame (have spell let me post question) site please say. have tested out i-frame never seems work. maybe counter when reaching 14 revert 1 again. thank in advance!
you should able achieve pure javascript using following:
date.prototype.getweek = function() { var onejan = new date(this.getfullyear(),0,1); var today = new date(this.getfullyear(),this.getmonth(),this.getdate()); var dayofyear = ((today - onejan +1)/86400000); return math.ceil(dayofyear/7) }; var sentences = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelvth", "thirsteenth", "fourteenth"]; var date = new date(); var day = (date.getday()+6)%7+1; day = day * ((date.getweek()%2)+1); document.getelementbyid("container").innerhtml = sentences[day-1];
fiddle: https://jsfiddle.net/04wha99e/1/
using simple javascript, create array of sentences wish have, , current day of week (javascript date.getday() returns sunday 0, hence workaround) , based on week number being odd or multiply 1 on 2 getting range of 1-14 , return sentence array (starting index 0, hence minus 1)
the above script assumes, have div id container, inner html gets replaced:
<div id="container"> sentence goes </div>
Comments
Post a Comment