This is a Node.js API client to fetch multiple riddles from the [Riddles API].
You can specify the number of riddles you want to retrieve by passing a count
parameter in the query string.
GET http://localhost:3000/riddles?count=5
[
{
"riddle": "A phone rings 9 times, and no one answers it. A horse eats 9 pounds of grain. A bannana grows 9 inches every day. and the computer gets 9 mail messages every day. What is always in the above paragraph?",
"answer": "Letters and words"
},
{
"riddle": "What can you catch but not throw?",
"answer": "A cold"
},
{
"riddle": "What falls but doesn't break, and what breaks but doesn't fall?",
"answer": "Night and Day"
},
{
"riddle": "A boy was at a carnival and went to a booth where a man said to the boy, “If I write your exact weight on this piece of paper then you have to give me $50, but if I cannot, I will pay you $50.” The boy looked around and saw no scale so he agrees, thinking no matter what the carny writes he'll just say he weighs more or less. In the end the boy ended up paying the man $50. How did the man win the bet?",
"answer": "The man did exactly as he said he would and wrote “your exact weight”on the paper"
},
{
"riddle": "What word can be written forward, backward or upside down, and can still be read from left to right?",
"answer": "NOON"
}
]
-
GET /riddles?count=[count]
- Fetches the specified number of riddles.
-
POST /check-answer
- Compares the user's answer with the correct answer for a specific riddle.
-
Check answer:
POST http://localhost:3000/check-answer Content-Type: application/json { "riddle": { "riddle": "A boy was at a carnival...", "answer": "The man did exactly as he said he would..." }, "userAnswer": "He wrote your exact weight" }
{
"message": "Correct answer!"
}
Or, if the answer is incorrect:
{
"message": "Incorrect answer. Try again!"
}
Once the server is running, you can test the check-answer API by sending a POST request to the /check-answer endpoint with a riddle object and the user's answer in the request body. The server will compare the normalized answers and respond with either a confirmation of correctness or a prompt to try again.
You can use tools like Postman or Insomnia, or write a frontend to send requests to the backend.