#!/usr/bin/env node; /****************************************************************************** * This program prints the lyrics to Farmer in the Dell * using a map to store the data. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ const PEOPLE = new Map([ ["farmer", "wife"], ["wife", "child"], ["child", "nurse"], ["nurse", "cow"], ["cow", "dog"], ["dog", "cat"], ["cat", "mouse"], ["mouse", "cheese"] ]); const main = async () => { let person = "farmer"; console.log("The famer in the dell"); console.log("The famer in the dell"); console.log("Hi-ho, the derry-o..."); console.log("The famer in the dell"); console.log(); while (person !== "cheese") { const OTHER_PERSON = PEOPLE.get(person); console.log(["The ", person, " takes the ", OTHER_PERSON].join('')); console.log(["The ", person, " takes the ", OTHER_PERSON].join('')); console.log("Hi-ho, the derry-o..."); console.log(["The ", person, " takes the ", OTHER_PERSON].join('')); console.log(); person = OTHER_PERSON; } console.log("The cheese stands alone"); console.log("The cheese stands alone"); console.log("Hi-ho, the derry-o..."); console.log("The cheese stands alone"); } main().catch( e => { console.error(e) } );