Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                


              
            
!

CSS

              
                
ol
	margin: 30px 0
	list-style: none
	max-width: 500px
	li
		padding: 10px
		border-radius: 5px
		& + li
			margin-top: 20px
		h2, h3
			margin: 0
			padding: 0
		.date
			color: gray
		&.lesson
			background-color: lightgreen
		&.day-off
			background: lightgray
		&:first-of-type
			background: cyan
		&.unfinished
			background: red
			color: white
			opacity: .2

              
            
!

JS

              
                console.clear();
// thinking through some drip content
// ...



// https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
const _MS_PER_DAY = 1000 * 60 * 60 * 24;

// a and b are javascript Date objects  start/today
function dateDifferenceInDays(a, b) {
  // Discard the time and time-zone information.
  const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
  const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
  return Math.floor((utc2 - utc1) / _MS_PER_DAY) + 1; // if the start date is today... then still need to see a lesson...
}




const TODAY_DATE = new Date();
const START_DATE = new Date('February 25, 2021'); // SWITCH THIS to different mondays to test... 9, 16, 23
const DAYS_PASSED = dateDifferenceInDays(START_DATE, TODAY_DATE);
console.log('days passed', DAYS_PASSED, " should show ", DAYS_PASSED, " days");


// There will be in-between 20 and 144 lessons per class
// I want there to be a decided day of the week that we do not work
// By default - this could be Sunday / but - I'm open to certain groups choosing a different day.
// ...so, I'd like to be prepared to choose that - instead of hard-coding it.
const exampleLessons = [
	{name: 1},{name: 2},{name: 3},{name: 4},{name: 5},{name: 6},
	{name: 7},{name: 8},{name: 9},{name: 10},{name: 11},{name: 12},
	{name: 13},{name: 14},{name: 15},{name: 16},{name: 17}
];


// cut out the right span of lessons based on start date / daysPassed
function curateList(lessons) {
	if (lessons.length > DAYS_PASSED) {
		return lessons.splice(0, DAYS_PASSED);
	} else {
		var unfinished = DAYS_PASSED - lessons.length;
		console.log('unfinished', unfinished);
		while(unfinished > 0) {
			lessons.push({
				type: "unfinished",
				name: "unfinished",
			});
			unfinished--;
		}
		return lessons; // should they be padded... to show what isn't done for the teacher?
	}
}

// console.log('c', curateList(exampleLessons) );


// put the days-off in there - and create a new array of all days and non-days
function setupDayOff(list) {
	// break up lists into groups of 6?
	var chunks = [];
	var cut = 0; // where to slice it... 
	var total = list.length;
	var final = [];
	console.log('f', final);

	while (cut < total) {
		chunks.push( list.slice(cut, cut += 6) );
		console.log('cut', cut);
	}

	chunks.forEach( function(chunk) {
		if (chunk.length == 6) {
			chunk.push({
				type: "day-off",
				name: "No working today!",
			});
		}
		final.concat(chunk);
		final = [...final, ...chunk];
	});
	return final;
}

Date.prototype.addDays = function(days) {
	var date = new Date(this.valueOf());
	date.setDate(date.getDate() + days);
	return date;
}

function renderList() {
	var available = setupDayOff( curateList(exampleLessons) );
	if (!available.length) return document.body.innerHTML = "Nooooooo!!!!";
	console.log('available', available);
	var open = `<ol class='lesson-list'>`;
	var items = '';
	available.forEach( function(day, index) {
		var item = '';
		var date = START_DATE.addDays(index);
		if (day.type == 'day-off') {
			item = `
				<li class='day-off'>
					<h3>${date}</h3>
					<h2>Day to relax</h2>
				</li>
			`;
		} else if (day.type == 'unfinished') {
			item = `
				<li class='unfinished'>
					<h3>${date}</h3>
					<h2>Unfinished</h2>
				</li>
			`;
		} else {
			item = `
				<li class='lesson'>
					<h3>${date}</h3>
					<h2>Lesson number ${day.name}</h2>
				</li>
			`;
		}
		items = item + items;
	});
	var close = `</ol>`
	document.body.innerHTML = open + items + close;
}



renderList( exampleLessons );

              
            
!
999px

Console