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

Conversation

@khaledkzy
Copy link

No description provided.

Copy link
Contributor

@kabaros kabaros left a comment

Choose a reason for hiding this comment

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

This a very good PR @khaledkzy .. the comments are just to improve details but all in all, it does what it is supposed to do in an elegant way.

Read the comments, and let me know if you have questions and update your PR with the changes requested.

</div>
</div>

<script type="text/javascript" src="main.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you put the script tag in bottom not in top? (trick question)

Copy link
Author

Choose a reason for hiding this comment

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

Because when you put it at the end it means that the javascript will only run in your page once the page is fully loaded.

var content = document.querySelector('#mybutton');
function showHide(event) {
event.preventDefault();
if (content.className === "hide") {
Copy link
Contributor

Choose a reason for hiding this comment

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

very good simple logic

main.js Outdated
//Show and Hide The news Sections
var controlElement = document.querySelector('#show');
controlElement.addEventListener('click', showHide);
var content = document.querySelector('#mybutton');
Copy link
Contributor

Choose a reason for hiding this comment

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

variable names are confusing - why are you 'mybutton' content?

index.html Outdated


<p><a href="#" id="show">Show/Hide news items</a></p>
<div class="content" id="mybutton">
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you giving an id mybutton to something that is not a button?

Copy link
Contributor

Choose a reason for hiding this comment

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

also in general don't use things like "my" in variable names - this is bad practice

main.js Outdated
sbumitButton.addEventListener('click', submitForm);

function submitForm(event) {
event.preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

bad indentation - format your document!

main.js Outdated
}

function verifyUserName() {
if (userName.value.length <= 0 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this check can also be ... if(!userName.value) (notice the !)

main.js Outdated
}

function verifyUserEmail() {
if (userEmail.value.length <= 0 || textEmail.value.indexOf('@') < 0 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is good but you could also write it like this

var isEmailValid = (userEmail.value.length <= 0 || textEmail.value.indexOf('@') < 0);
userEmail.style.backgroundColor = isEmailValid ? 'red' : 'white'; // if you don't understand this code - google ternary operators in JavaScript
return isEmailValid; // this will be false or true

This code is necessarily better or worse, but just read it and make sure you understand it (it should be equivalent to your code) and let me know if you have questions about it


// AJAX REQUEST

var xhrcontent = document.getElementsByClassName(content);
Copy link
Contributor

Choose a reason for hiding this comment

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

very good!

Now as an extra challenge .. use fetch to make the AJAX call - see how much simpler you code becomes. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

(fetch doesn't work in older browsers but we don't care about that - http://caniuse.com/#feat=fetch)

style.css Outdated
margin-bottom: 20px;
}
a {
text-decoration: none !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

in general, don't use !important - if you work in a team and use !important, people will hate you. Just use a class name to your a tags, and use that class name for styling

style.css Outdated
}

.new .title{
color: white;
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation! format your document

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