Last active
October 4, 2023 11:14
-
-
Save burnoutprojects/39614e0cf89ea7c33665f6b272191099 to your computer and use it in GitHub Desktop.
Percentage of the year with ascii bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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