Last active
December 14, 2015 15:38
-
-
Save jhixson/7294fb508ebb2e578906 to your computer and use it in GitHub Desktop.
Pretty straightforward twelve days of Christmas implementation in JS with a few ES6 bits.
This file contains hidden or 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 gifts = ['partridge in a pear tree', 'turtle doves', 'french hens', 'calling birds', 'GOLDEN RINGS', 'geese-a-laying', 'swans-a-swimming', 'maids-a-milking', 'ladies dancing', 'lords-a-leaping', 'pipers piping', 'drummers drumming']; | |
const ordinals = ['first','second','third','fourth','fifth','sixth','seventh','eighth','ninth','tenth','eleventh','twelfth']; | |
const numbersToWords = ['One','Two','Three','Four','FIVE','Six','Seven','Eight','Nine','Ten','Eleven','Twelve']; | |
function twelveDays() { | |
for(var i = 0; i < gifts.length; i++) { | |
console.log(`On the ${ordinals[i]} day of Christmas,\nMy true love gave to me,`); | |
if(i == 0) { | |
console.log(`a ${gifts[0]}.\n`); | |
} | |
else { | |
giftForDays(i); | |
} | |
} | |
} | |
function giftForDays(day) { | |
if(day == 0) { | |
console.log(`And a ${gifts[0]}.\n`); | |
} | |
else { | |
console.log(`${numbersToWords[day]} ${gifts[day]},`); | |
giftForDays(day-1); | |
} | |
} | |
twelveDays(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment