This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
part 1 of js/homework #6
Open
anthonythuo2320
wants to merge
1
commit into
CodeYourFuture:master
Choose a base branch
from
anthonythuo2320:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| function getMessage() { | ||
| var textBox = document.querySelector('.addArticle'); | ||
| var request = new XMLHttpRequest(); //creating a request object | ||
|
|
||
| request.onreadystatechange = function () { | ||
| if (request.readyState === 4) { // check if a response was sent back | ||
| if (request.status === 200) { // check if request was successful | ||
| textBox.value = request.responseText; | ||
| } else { | ||
| textBox.value = 'An error occurred during your request: ' + request.status + ' ' + request.statusText; | ||
| } | ||
| } | ||
| } | ||
| var url = "http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=yohannes"; //server location | ||
| request.open("GET", url); // adding it to the request | ||
|
|
||
| request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //header info | ||
| request.send(); // sending the request | ||
| } | ||
|
|
||
| var text = document.querySelector('#getMessageButton'); | ||
| text.addEventListener('click', getMessage); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
|
|
||
|
|
||
| function changeBackgroundColour(element, colour, ) { | ||
| element.style.backgroundColor = colour; | ||
| } | ||
| function changeFontColor(element, colour) { | ||
| element.style.color = colour; | ||
| } | ||
| function jumbotronColor(element, colour) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You aren't using this function. Maybe you don't need it and it can be removed? |
||
| element.style.backgroundColor = colour; | ||
| } | ||
|
|
||
| function changeColor(event) { | ||
| var jumbotron = document.querySelector('.jumbotron'); | ||
| var donateAbike = document.querySelector('.btn.btn-primary.btn-lrg'); | ||
| var volunteer = document.querySelector('.btn.btn-secondary.btn-lrg'); | ||
|
|
||
| if (event.target.id === "blueBtn") { | ||
| changeBackgroundColour(jumbotron, '#588fbd'); | ||
| changeBackgroundColour(donateAbike, '#ffa500'); | ||
| changeBackgroundColour(volunteer, 'black'); | ||
| changeFontColor(volunteer, 'white'); | ||
| } else if (event.target.id === 'orangeBtn') { | ||
| changeBackgroundColour(jumbotron, '#f0ad4e'); | ||
| changeBackgroundColour(donateAbike, '#5751fd'); | ||
| changeBackgroundColour(volunteer, '#31b0d5'); | ||
| changeFontColor(volunteer, 'white'); | ||
|
|
||
| } else if (event.target.id === 'greenBtn') { | ||
| changeBackgroundColour(jumbotron, '#87ca8a'); | ||
| changeBackgroundColour(donateAbike, 'black'); | ||
| changeBackgroundColour(volunteer, '#8c9c08'); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| var myButtons = document.querySelectorAll('.colorButton'); | ||
| for (var i = 0; i < myButtons.length; i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha :). Nice use of a for loop and if statements in the 'changeColor' function. |
||
| myButtons[i].addEventListener('click', changeColor); | ||
|
|
||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 1. Select element (using CSS selectors) | ||
| var myButton = document.querySelector('.jumbotron'); | ||
|
|
||
| // 2. Define your event handler (callback <-- function) | ||
| myButton.addEventListener('click', doSomething); | ||
|
|
||
| function doSomething(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could rename this function to something describing what it does. Maybe 'changePageElementColours' or something :P |
||
| var jumbotron = document.querySelector('.jumbotron'); | ||
| jumbotron.style.backgroundColor = 'red'; | ||
| } | ||
|
|
||
| var myButton = document.querySelector('#addToLearnMore'); | ||
| myButton.addEventListener('click', appendArticle); | ||
|
|
||
| function changeColor() { | ||
| var mainArticles = document.querySelector('#mainArticles'); | ||
| mainArticles.style.color = 'yellow'; | ||
| } | ||
|
|
||
| function appendArticle() { | ||
| var paragragh = document.createElement('p'); | ||
| paragragh.innerText = 'My name is Anthony and am a student'; | ||
|
|
||
| var mainArticles = document.querySelector("#mainArticles"); | ||
| mainArticles.appendChild(paragragh); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ',' after colour is not valid javascript. Maybe it breaks your function?