another javascript solution that didnt pan out
working js solution