Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Conversation

LexiisYing
Copy link

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

server.js Outdated
res.json(findId);
console.log(findId);
} else {
res.status(404).send("Message not found");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of status message

server.js Outdated
app.get("/messages/:id", function(req, res) {
const messageId = req.params.id;
const findId = messages.find((message) => { return message.id === Number(messageId) });
if (findId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny formatting error where "if" isn't lined up with const but don't worry about that for now!


console.log(newMessage);
messages.push(newMessage);
res.status(201).json({ success: true, data: messages });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

if (findIndex === -1) {
res.status(404).send("Message not found");
} else {
messages.splice(findIndex, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks good!

app.post("/messages", function (req, res) {
const {from, text} = req.body
const newMessage = {
id: messages.length,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When setting the ID this way, what would happen if you add 3 messages, deleted the first one, then tried to add another?

ie messages = [1, 2, 3] then remove one -> [2, 3] then try to add a new one -> [2, 3, ?]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants