-
-
Notifications
You must be signed in to change notification settings - Fork 12
Web Developer Test #1
base: master
Are you sure you want to change the base?
Conversation
…t will become red
|
I have done all issues about functions and some change in HTML code |
kabaros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good submission @MrDwina .. I have added some comments to improve the code. Please do them and update your PR.
Also a general comment about your commit messages. Your commits are way too small, you shouldn't have one big massive commit but you shouldn't also have lots of commits of a single line. The commits should be some set of functionality that makes sense together (for example in case you need to revert a commit) - for example, in this exercise, one could have been for HTML, other for CSS, one for hide functionality, another for AJAX then several for the code reviews. But not more than that.
css/style.css
Outdated
| margin: 5px 0; | ||
| } | ||
| /*=============== Media query ================*/ | ||
| @media (max-width : 391px){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you following a mobile-first approach? Normally if you are then you wouldn't need a media query for less than 390px, unless you're targeting an even smaller screen.
css/style.css
Outdated
| /*============ Start Header ==============*/ | ||
| .logo{ | ||
| padding: 40px 0 50px 0; | ||
| font-size: 60px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using px as your unit, use em or rem. This will make your CSS scale better in a responsive design. Google "em" and "rem" if you don't know them.
| </ul> | ||
| </nav> | ||
| <article> | ||
| <h1 class="about-cyf">About CYF</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good class names - you are very consistent (using lower case and dashes all the time). This is very good and important.
js/customer.js
Outdated
| const email = document.getElementById('email'); | ||
| const phoneNumber = document.getElementById('phoneNumber'); | ||
| function validEmail (email) { | ||
| return email.value.indexOf("@") !== 0 && email.value.indexOf("@") !== -1 && email.value.indexOf(".") !== -1 && email.value.lastIndexOf("@") < email.value.lastIndexOf(".") && email.value.lastIndexOf(".") < (email.value.length - 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you google "Regular Expressions" to validate the email. Find a Regex that validates and use it. If you need explanation of how it works, then let us know.
js/customer.js
Outdated
| alert('Thank you for register with us'); | ||
| // If the name, email and contact number are not valid execute this code | ||
| /*====================================================================*/ | ||
| }else if (!validName(name) && !validPhoneNumber(phoneNumber) && !validEmail(email)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all those else ifs are unnecessary and complicate the logic. You don't need to check all of three validations every time, the logic will be simpler if you do it one by one. Also instead of using style.background - create a CSS class called .error and add/remove it depending on the logic. If you do that, then if you decide to change how an error style looks like, you just use the CSS in one place.
So the logic should look something like.
if(!validName) {
// apply error style
} else {
// remove error style
}
if(!validEmail) {
// apply error style
} else {
// remove error style
}
//etc..This code can be much simpler than this
js/customer.js
Outdated
| resivedNews.style.display = 'none'; | ||
| const showNews = document.querySelector('#showNews'); | ||
| const url = "https://private-e99507-kabaros.apiary-mock.com/news"; | ||
| var request = new XMLHttpRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use const/let then be consistent with that - don't use var
(also there is some indentation issues with this code - format the document)
js/customer.js
Outdated
| } | ||
| resivedNews.style.display = 'block'; | ||
| }else { | ||
| console.log(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty console.log
js/customer.js
Outdated
| request.send(); | ||
| }); | ||
|
|
||
| const hideNews = document.querySelector('#hideNews'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the requirement was to use the same link to show/hide .. so when you click first time, it shows the div, then the second time, it hides it. Can you update your code to do that please
| }else { | ||
| alert('error'); | ||
| return false; | ||
| if (validName(name) && validName(name) && validPhoneNumber(phoneNumber)) { alert('Thank you for register with us')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to call validName(name) etc.. every time. Just put the value in a variable and use it. So
var isNameValid = validName(name);
var isEmailValid = validEmail(email);
var isPhoneValid = validPhone(email);
// then
if(isNameValid && isEmailValid && isPhoenValid) {
}| if (validName(name) && validName(name) && validPhoneNumber(phoneNumber)) { alert('Thank you for register with us')} | ||
|
|
||
| if (validName(name)) { | ||
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong logic .. if you have return then you will never get to the next line - you will never remove the calss 'error'. There is no need to return in any of these checks.
| const showAndHide = document.querySelector('#showAndHide'); | ||
| showAndHide.addEventListener('click', function (event) { | ||
| event.preventDefault(); | ||
| resivedNews.classList.toggle('hiddenShow'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good use of toggle
| hideNews.addEventListener('click', function () { | ||
| resivedNews.style.display = 'none'; | ||
| const request = new XMLHttpRequest(); | ||
| request.onreadystatechange = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tried using fetch for the AJAX call?
I created the page in responsive way, it open nicely on different devices.
I would like to get feedback if there is any additional styling, then I will complete the JavaScript code.