Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Have completed the first homework#3

Open
wonmaungthein wants to merge 7 commits into
CodeYourFuture:masterfrom
wonmaungthein:master
Open

Have completed the first homework#3
wonmaungthein wants to merge 7 commits into
CodeYourFuture:masterfrom
wonmaungthein:master

Conversation

@wonmaungthein

Copy link
Copy Markdown

Hello mentors,
Good evening. I hope you are fine. Could you please check if my codes are ok? Thank you so much for all your help.

Kind Regards,
Won

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In general, pretty good job. Minor comments added.

Comment thread js/homework.js
}

// Making changes when clicking orange button.*/
var orangeButton = document.querySelector('#orangeBtn');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I prefer to move the var declarations to the top of the file or function.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same goes for greenButton, submitButton... etc.

Comment thread js/homework.js

// Setting the form is Valid by using boolean.(true)
var formIsValid = true;
/* if the namebox with value.length is invalid, changed background color of box to red

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Long comments tend to indicate that a part of the code can be replaced by an inner function.

The nameboxMv if statement can be replaced by a function like "isNameValid" returning true or false depending on the case.

You can apply the same for email and description. This reduces this function complexity and removes the need of comments.

I will elaborate more in the next comment.

Comment thread js/homework.js

/* if the form is valid, alert (" thanks "), change namebox, describeYourself
and email's value to empty string value.*/
if (formIsValid) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we replace each function for a boolean check function, then we can replace this code for:
if (isNameValid() && isEmailValid() && isDescribeYourselfValid()) {

The implementation can still be the same a part from formIsValid = false that is not needed anymore.

The reason of doing so is to make it easier to expand other validations and to read and maintain the code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you so much for your time to check the code and giving very useful advices.. :) :) I will edit them.. :) 👍

Comment thread js/main.js
}
}
}
var url = "http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=c"; //server location

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

redundant

Comment thread js/main.js


// This works. Posting, Sending (params) to Server
var request = new XMLHttpRequest(); //creating a request object

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By creating an object twice, only the last implementation will be use. (1st one will be discarded)

Make sure that is what you want, otherwise use the same request object or create a 'postRequest, getRequest'

Comment thread js/main.js
request.onreadystatechange = function () {
if (request.readyState === 4) { // check if a response was sent back
if (request.status === 200) { // check if request was successful
document.querySelector(".display-3").innerHTML = JSON.parse(request.responseText)['message'];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to follow always the same patter. If you are assiging the querySelector to a variable, do it across all your code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants