Created
November 30, 2019 07:34
-
-
Save jimmycrequer/c845f1e82dbfda62c61b736b9469f542 to your computer and use it in GitHub Desktop.
geography-guessCountryFromNeighbors
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
async function guessCountryFromNeighbors() { | |
await session | |
.run(` | |
MATCH (c:Country)-[:IS_NEIGHBOR_OF]-(n:Country) | |
WITH c.name AS country, collect(n.name) AS neighbors | |
RETURN country, neighbors | |
`) | |
.then(res => { | |
const i = Math.round(Math.random() * res.records.length - 1) | |
const country = res.records[i].get('country') | |
const neighbors = res.records[i].get('neighbors') | |
const answer = readlineSync.question(`Which country is bordered by ${neighbors}?\n> `) | |
if (answer == country) | |
console.log('\x1b[32m%s\x1b[0m', 'Correct!') | |
else | |
console.log('\x1b[33m%s\x1b[0m', `Wrong! The answer is ${country}.`) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment