Hey Chris, great work with this lab, here are my implementations below, compare to yours, let me know if you have any questions!
app.get("/magic/:question", (req, res) => {
const answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes definitely",
"You may rely on it",
"As I see it yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful",
];
const randomIndex = Math.floor(Math.random() * answers.length);
log(randomIndex);
const { question } = req.params;
log(question);
log(encodeURIComponent(question)); //converts any string into URL friendly format
res.send(<h1>${answers[randomIndex]}</h1>);
});
app.get("/tip/:bill/:tipPercent", (req, res) => {
const { bill, tipPercent } = req.params;
log(Your bill is ${bill} and your tip percent is ${tipPercent});
res.status(200).json((tipPercent / bill) * 100);
});
Hey Chris, great work with this lab, here are my implementations below, compare to yours, let me know if you have any questions!
app.get("/magic/:question", (req, res) => { const answers = [ "It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it yes", "Most likely", "Outlook good", "Yes", "Signs point to yes", "Reply hazy try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful", ]; const randomIndex = Math.floor(Math.random() * answers.length); log(randomIndex);
const { question } = req.params; log(question); log(encodeURIComponent(question)); //converts any string into URL friendly format res.send(
<h1>${answers[randomIndex]}</h1>
); });app.get("/tip/:bill/:tipPercent", (req, res) => { const { bill, tipPercent } = req.params; log(
Your bill is ${bill} and your tip percent is ${tipPercent}
); res.status(200).json((tipPercent / bill) * 100); });//--------------------------------------------------------------- app.get("/:bottles", (req, res) => { const { bottles } = req.params; const link = bottles <= 0 ? 99 : bottles - 1;
res.send(`
${bottles} Bottles of Beer of the wall
take one down, pass it around `); });