Skip to content

Instantly share code, notes, and snippets.

@jimmycrequer
Created November 30, 2019 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmycrequer/0f7c1e708e30e3cba275d13efd4c82be to your computer and use it in GitHub Desktop.
Save jimmycrequer/0f7c1e708e30e3cba275d13efd4c82be to your computer and use it in GitHub Desktop.
geography-guesscontryfromcapital
async function guessCountryFromCapital() {
await session
.run(`
MATCH p = (:Country)<-[:IS_CAPITAL_OF]-(:City)
RETURN apoc.coll.randomItem(collect(p)) AS p
`)
.then(res => {
const p = res.records[0].get('p')
const capitalName = p.end.properties.name
const countryName = p.start.properties.name
const answer = readlineSync.question(`Which country has ${capitalName} as capital?\n> `)
if (answer == countryName)
console.log('\x1b[32m%s\x1b[0m', 'Correct!')
else
console.log('\x1b[33m%s\x1b[0m', `Wrong! The answer is ${countryName}.`)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment