Skip to content

Instantly share code, notes, and snippets.

@burnoutprojects
Last active October 4, 2023 11:14
Show Gist options
  • Save burnoutprojects/39614e0cf89ea7c33665f6b272191099 to your computer and use it in GitHub Desktop.
Save burnoutprojects/39614e0cf89ea7c33665f6b272191099 to your computer and use it in GitHub Desktop.
Percentage of the year with ascii bar
const curYear = new Date().getFullYear()
const start = new Date(curYear, 0, 1);
const end = new Date(curYear, 11, 31);
const today = new Date();
const percent = Math.floor(((today - start) / (end - start)) * 100);
let bar = '';
for (i = 0.5; i <= 10; i += 0.5) {
if ((percent / (i * 10)) >= 1.0) {
bar += '▓';
} else {
bar += '▒';
}
}
alert(`${bar}\n${percent}% of the year have already passed.\n${100 - percent}% of the year are still ahead.`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment