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

Conversation

@softacoder
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?

@softacoder softacoder changed the title London10_Jan_Softa_Node.js_Week2_CYF_Chat_React London10_Jan_Softa_Node.js_Week2_CYF_Chat_Server Jul 26, 2023
Copy link

@giorgiguts giorgiguts left a comment

Choose a reason for hiding this comment

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

Excellent work! You've clearly demonstrated that you understand core concepts of AJAX calls, CRUD operations and the fundamentals of building effective Restful APIs. Keep up the great work! 😊

<script>
function deleteMessage() {
const idToDelete = document.getElementById("deleteId").value;
if (!idToDelete || isNaN(idToDelete)) {

Choose a reason for hiding this comment

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

Great use of a guard clause! 🥳 it's very important to have these layers of security throughout our codebase, to minimise the amount of bugs, and stop our program from crashing. Excellent work!

<button type="button" onclick="deleteMessage()">Submit</button>
</form>

<script>

Choose a reason for hiding this comment

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

Just as a suggestion, we can create a separate javascript file, for example script.js and then refer or include that exact javascript file into the script HTML element. You can read more on that here for example. This way, we can effectively structure our code.

fetch(url, {
method: "DELETE",
})
.then((response) => {

Choose a reason for hiding this comment

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

Also, as a suggestion and going forward with JavaScript, is to get acquainted with ES6+ features and apply them to your JS solutions. One of the ES6+ features (which generally means modern JavaScript) is the use of async/await functions. There's this amazing instructor Colt Steele out there on Youtube, and I highly suggest you watch this tutorial on how to use it, here's the link. He has really comprehensive and easy-to-follow tutorials on his Youtube channel. 10/10 recommended 🥹

The idea of using async/await is to make your codebase shorter and thus easier to understand. 😊

app.get("/messages/:id", (req, res) => {
const getById = Number(req.params.id);
const findByID = messages.find((message) => message.id === getById);
if (!findByID)

Choose a reason for hiding this comment

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

Again, excellent use of a guard clause! 🥳

const { from, text } = req.body;

// Check if the 'from' and 'text' properties are present and not empty
if (!from || !text || from.trim() === "" || text.trim() === "") {

Choose a reason for hiding this comment

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

This is very smart. Just because we don't have power over what user may type, we are anticipating and trimming any excess whitespace. Great work 💪

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants