From 1d1631624a8626b9b896b3c5726b35a6bda02059 Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Sun, 18 Jun 2017 14:54:00 +0100 Subject: [PATCH 1/7] Started homework. My present code is not working.. Will need help and sort out soon. --- js/homework.js | 43 +++++++++++++++++++++ js/main.js | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/js/homework.js b/js/homework.js index e69de29..efeeaab 100644 --- a/js/homework.js +++ b/js/homework.js @@ -0,0 +1,43 @@ + +// Homework for the Bike for Refugee. This code is not working. +var blueButton = document.querySelector("#blueBtn"); +blueButton.addEventListener("click", changeTheme); + +function changeTheme() { + .jumbotron.style.backgroundColor = '#588fbd'; +} + + +// Didn't seem to be working. +var donateButton = document.querySelector(".btn-primary"); +donateButton.addEventListener("click", changeColor1); + +function changeColor1() { + donateButton.style.backgroundColor = '#ffa500'; +} + + + +var volunteerButton = document.querySelector(".btn-secondary"); +volunteerButton.addEventListener("click", changeColor2); + +function changeColor2() { + volunteerButton.style.backgroundColor = 'black'; +} + +// This didn't work out, need help +var volunteerFont = document.querySelector("Volunteer"); +volunteerFont.addEventListener("click", changeFontColor); + +function changeFontColor() { + volunteerFont.style.backgroundColor = 'white'; +} + + +// Not working +var orangeButton = document.querySelector("#orangeBtn"); +orangeButton.addEventListener("click", changeBackgroundColor); + +function changeBackgroundColor() { + jumbotron.style.backgroundColor = "#f0ad4e"; +} \ No newline at end of file diff --git a/js/main.js b/js/main.js index e69de29..d885cd7 100644 --- a/js/main.js +++ b/js/main.js @@ -0,0 +1,101 @@ + +// Setting an alert +var learnMoreButton = document.querySelector("#addToLearnMore"); +learnMoreButton.addEventListener("click", ShowMore); + +function ShowMore() { + alert("Thanks for finding out more about us"); +} + +// Setting an alert +var images = document.querySelector("#allImages"); +images.addEventListener("click", seeImages); + +function seeImages() { + alert("There you go, enjoy all our photos"); +} + +// changing background colour +var boxColor = document.querySelector(".jumbotron"); +boxColor.addEventListener('click', changeColor); + +function changeColor() { + boxColor.style.backgroundColor = 'yellow'; + + var paragraph = document.createElement('p'); + paragraph.innerText = "SHOW ME MORE JAVASCRIPT"; + + boxColor.appendChild(paragraph); +} + +var learnButton = document.querySelector("#addToLearnMore"); +learnButton.addEventListener('click', addParagraph); + +function addParagraph() { + + var newParagraph = document.createElement('p'); + newParagraph.innerText = "SHOW ME MORE We need lots of bike what are the tricks"; + + var topOfArticle = document.querySelector('#mainArticles'); + topOfArticle.appendChild(newParagraph); +} + +var allImagesbutton = document.querySelector("#allImages"); +allImagesbutton.addEventListener("click", showAllImages); + +function showAllImages() { + var selectingAllimg = document.querySelectorAll("img"); + for (var i = 0; i < selectingAllimg.length; i++) { + selectingAllimg[i].width = selectingAllimg[i].width - 10; + selectingAllimg[i].height = selectingAllimg[i].height - 10; + } +} +// It's not working. +var boxColor = document.querySelector(".jumbotron"); +boxColor.addEventListener('click', changeColor); + +function changeColor() { + boxColor.className += " blue"; +} + + +// This works. Posting, Sending (params) to Server +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 + document.querySelector(".display-3").innerHTML = request.responseText; + } else { + alert('An error occurred during your request: ' + request.status + ' ' + request.statusText); + } + } +} +var url = "http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=c"; //server location +var params = "Hello Mohamed and Nasir. What are you going to do now"; // content we want to send +request.open("POST", url, true); // adding them to the request + +request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //header info +request.send(params); // sending the request + + + + +// Getting/receiving the data from the server +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 + document.querySelector(".display-3").innerHTML = JSON.parse(request.responseText)['message']; + } else { + alert('An error occurred during your request: ' + request.status + ' ' + request.statusText); + } + } +} +var url = "http://ajax-cyf.eu-west-1.elasticbeanstalk.com/chatroom/?id=c"; //server location +// var params = "Hello"// content we want to send +request.open("GET", url);// adding them to the request +request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //header info +request.send(); // sending the request + + + From 383706e40908e849b698ff524d7b719db564a48c Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Mon, 19 Jun 2017 08:17:33 +0100 Subject: [PATCH 2/7] have made some changes in homework part 1 --- homework.html | 1 + js/homework.js | 101 ++++++++++++++++++++++++++++++++++++------------- js/main.js | 16 +++++--- 3 files changed, 87 insertions(+), 31 deletions(-) diff --git a/homework.html b/homework.html index 926360a..dd5aec2 100644 --- a/homework.html +++ b/homework.html @@ -3,6 +3,7 @@ Bikes for Refugees | Scotland + diff --git a/js/homework.js b/js/homework.js index efeeaab..4af67fc 100644 --- a/js/homework.js +++ b/js/homework.js @@ -1,43 +1,92 @@ -// Homework for the Bike for Refugee. This code is not working. -var blueButton = document.querySelector("#blueBtn"); -blueButton.addEventListener("click", changeTheme); +/* Homework for the Bike for Refugee. This code is partly working. + Making changes when clicking blue button.*/ +var blueButton = document.querySelector('#blueBtn'); +blueButton.addEventListener('click', changeToBlue); +var box = document.querySelector('.jumbotron'); +var donateButton = document.querySelector(".btn.btn-primary.btn-lrg"); +var volunteerButton = document.querySelector(".btn.btn-secondary.btn-lrg"); -function changeTheme() { - .jumbotron.style.backgroundColor = '#588fbd'; +function changeToBlue() { + box.style.backgroundColor = '#588fbd'; + donateButton.style.backgroundColor = '#ffa500'; + volunteerButton.style.backgroundColor = 'black'; + volunteerButton.innerHTML.backgroundColor = 'white'; } -// Didn't seem to be working. -var donateButton = document.querySelector(".btn-primary"); -donateButton.addEventListener("click", changeColor1); +// Making changes when clicking orange button.*/ +var orangeButton = document.querySelector('#orangeBtn'); +orangeButton.addEventListener('click', changetoOrange); -function changeColor1() { - donateButton.style.backgroundColor = '#ffa500'; +function changetoOrange() { + box.style.backgroundColor = '#f0ad4e'; + donateButton.style.backgroundColor = '#5751fd'; + volunteerButton.style.backgroundColor = '#31b0d5'; + volunteerButton.innerHTML.backgroundColor = 'white'; } +// Making changes when clicking green button. +var greenButton = document.querySelector('#greenBtn'); +greenButton.addEventListener('click', changeToGreen); -var volunteerButton = document.querySelector(".btn-secondary"); -volunteerButton.addEventListener("click", changeColor2); +function changeToGreen() { + box.style.backgroundColor = '#87ca8a'; + donateButton.style.backgroundColor = 'black'; + volunteerButton.style.backgroundColor = '#8c9c08'; + volunteerButton.innerText.backgroundColor = 'white'; +} -function changeColor2() { - volunteerButton.style.backgroundColor = 'black'; +// Selecting the submit button and validating the form. +var submitButtom = document.querySelector("button.btn.btn-primary"); +submitButtom.addEventListener('click',validateTheForm); +function validateTheForm() { +alert("selected the right button."); } -// This didn't work out, need help -var volunteerFont = document.querySelector("Volunteer"); -volunteerFont.addEventListener("click", changeFontColor); -function changeFontColor() { - volunteerFont.style.backgroundColor = 'white'; -} +// // Didn't seem to be working. +// var donateButton = document.querySelector(".btn-primary"); +// donateButton.addEventListener("click", changeColor1); + +// function changeColor1() { +// donateButton.style.backgroundColor = '#ffa500'; +// } + + + +// var volunteerButton = document.querySelector(".btn-secondary"); +// volunteerButton.addEventListener("click", changeColor2); + +// function changeColor2() { +// volunteerButton.style.backgroundColor = 'black'; +// } + + + + +// // This didn't work out, need help +// var volunteerFont = document.querySelector("Volunteer"); +// volunteerFont.addEventListener("click", changeFontColor); + +// function changeFontColor() { +// volunteerFont.style.backgroundColor = 'white'; +// } + + +// // Not working +// var orangeButton = document.querySelector("#orangeBtn"); +// orangeButton.addEventListener("click", changeBackgroundColor); +// function changeBackgroundColor() { +// jumbotron.style.backgroundColor = "#f0ad4e"; +// } -// Not working -var orangeButton = document.querySelector("#orangeBtn"); -orangeButton.addEventListener("click", changeBackgroundColor); +// var jumbBackground = document.querySelector('#jumbotronId'); +// var domanteButon = document.querySelector('#domantButtonId'); +// domanteButon.addEventListener('click', addBackground); +// function addBackground() { +// jumbBackground.style.backgroundColor = 'black'; +// } -function changeBackgroundColor() { - jumbotron.style.backgroundColor = "#f0ad4e"; -} \ No newline at end of file diff --git a/js/main.js b/js/main.js index d885cd7..57294c6 100644 --- a/js/main.js +++ b/js/main.js @@ -50,15 +50,21 @@ function showAllImages() { selectingAllimg[i].height = selectingAllimg[i].height - 10; } } -// It's not working. -var boxColor = document.querySelector(".jumbotron"); -boxColor.addEventListener('click', changeColor); -function changeColor() { - boxColor.className += " blue"; +// Temporary code, testing now. Will need more explanation for this. +var myButton = document.querySelector("#donateBike"); + +myButton.addEventListener("click", doSomething); + +function doSomething() { + var box = document.querySelector(".jumbotron"); + if (!box.className.includes("red")) { + box.className += " yellow"; + } } + // This works. Posting, Sending (params) to Server var request = new XMLHttpRequest(); //creating a request object request.onreadystatechange = function () { From 91af42b24e664d78e4c6af937154194774a59df3 Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Mon, 19 Jun 2017 08:20:05 +0100 Subject: [PATCH 3/7] Deleted unnecessary comment --- js/homework.js | 47 ++--------------------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/js/homework.js b/js/homework.js index 4af67fc..0d67d19 100644 --- a/js/homework.js +++ b/js/homework.js @@ -38,7 +38,8 @@ function changeToGreen() { volunteerButton.innerText.backgroundColor = 'white'; } -// Selecting the submit button and validating the form. +/* Selecting the submit button and validating the form. +doesn't seem to be working.*/ var submitButtom = document.querySelector("button.btn.btn-primary"); submitButtom.addEventListener('click',validateTheForm); function validateTheForm() { @@ -46,47 +47,3 @@ alert("selected the right button."); } -// // Didn't seem to be working. -// var donateButton = document.querySelector(".btn-primary"); -// donateButton.addEventListener("click", changeColor1); - -// function changeColor1() { -// donateButton.style.backgroundColor = '#ffa500'; -// } - - - -// var volunteerButton = document.querySelector(".btn-secondary"); -// volunteerButton.addEventListener("click", changeColor2); - -// function changeColor2() { -// volunteerButton.style.backgroundColor = 'black'; -// } - - - - -// // This didn't work out, need help -// var volunteerFont = document.querySelector("Volunteer"); -// volunteerFont.addEventListener("click", changeFontColor); - -// function changeFontColor() { -// volunteerFont.style.backgroundColor = 'white'; -// } - - -// // Not working -// var orangeButton = document.querySelector("#orangeBtn"); -// orangeButton.addEventListener("click", changeBackgroundColor); - -// function changeBackgroundColor() { -// jumbotron.style.backgroundColor = "#f0ad4e"; -// } - -// var jumbBackground = document.querySelector('#jumbotronId'); -// var domanteButon = document.querySelector('#domantButtonId'); -// domanteButon.addEventListener('click', addBackground); -// function addBackground() { -// jumbBackground.style.backgroundColor = 'black'; -// } - From 07005cba7b99338b2255ed71c3d5dcf5af22874a Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Mon, 19 Jun 2017 14:32:39 +0100 Subject: [PATCH 4/7] able to select the submit button --- homework.html | 2 +- js/homework.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/homework.html b/homework.html index dd5aec2..52b7339 100644 --- a/homework.html +++ b/homework.html @@ -81,7 +81,7 @@

Bikes for Refugees

- +

Learn more

diff --git a/js/homework.js b/js/homework.js index 0d67d19..6464948 100644 --- a/js/homework.js +++ b/js/homework.js @@ -11,7 +11,6 @@ function changeToBlue() { box.style.backgroundColor = '#588fbd'; donateButton.style.backgroundColor = '#ffa500'; volunteerButton.style.backgroundColor = 'black'; - volunteerButton.innerHTML.backgroundColor = 'white'; } @@ -23,7 +22,6 @@ function changetoOrange() { box.style.backgroundColor = '#f0ad4e'; donateButton.style.backgroundColor = '#5751fd'; volunteerButton.style.backgroundColor = '#31b0d5'; - volunteerButton.innerHTML.backgroundColor = 'white'; } @@ -35,15 +33,20 @@ function changeToGreen() { box.style.backgroundColor = '#87ca8a'; donateButton.style.backgroundColor = 'black'; volunteerButton.style.backgroundColor = '#8c9c08'; - volunteerButton.innerText.backgroundColor = 'white'; } /* Selecting the submit button and validating the form. doesn't seem to be working.*/ -var submitButtom = document.querySelector("button.btn.btn-primary"); -submitButtom.addEventListener('click',validateTheForm); +var submitButtom = document.querySelector('#submitButton'); +submitButtom.addEventListener('click', validateTheForm); + function validateTheForm() { -alert("selected the right button."); + + var nameboxTag = document.querySelector(#example - text - input); + var namebox = document.querySelector('#example-text-input').value; + if (namebox.length === 0) { + nameboxTag.style.backgroundColor = '#8c9c08'; + } } From d57ccc34f0e99ad1ca5529ebadd07a80b9d68663 Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Mon, 19 Jun 2017 21:07:46 +0100 Subject: [PATCH 5/7] Have commented and formated the first homework. --- homework.html | 3 +- js/homework.js | 82 +++++++++++++++++++++++++++++++++------- js/main.js | 8 ++-- styles/homeworkStyle.css | 7 ++++ 4 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 styles/homeworkStyle.css diff --git a/homework.html b/homework.html index 52b7339..b5e03dc 100644 --- a/homework.html +++ b/homework.html @@ -12,6 +12,7 @@ + Skip to main content @@ -59,7 +60,7 @@

Bikes for Refugees


diff --git a/js/homework.js b/js/homework.js index 6464948..8baae98 100644 --- a/js/homework.js +++ b/js/homework.js @@ -1,52 +1,106 @@ -/* Homework for the Bike for Refugee. This code is partly working. - Making changes when clicking blue button.*/ +/* Homework for the Bike for Refugee. + Making changes when clicking blue button. + First selecting #blueBtn id and assign with blueButton. Adding addEventlistener to that blueButton + to changeToBlue when it's clicked. class .jumbotron was selected and assigned as box. donateButton, + volunteerButton and volunteerText were assigned to relevant variable.*/ var blueButton = document.querySelector('#blueBtn'); blueButton.addEventListener('click', changeToBlue); var box = document.querySelector('.jumbotron'); var donateButton = document.querySelector(".btn.btn-primary.btn-lrg"); var volunteerButton = document.querySelector(".btn.btn-secondary.btn-lrg"); +var volunteerTextColor = document.querySelector('.volunteerText'); +/* This is a function called "changeToBlue" which will change box's,donateButton's +, volunteerButton's background color and volunteerTextcolor.*/ function changeToBlue() { box.style.backgroundColor = '#588fbd'; donateButton.style.backgroundColor = '#ffa500'; volunteerButton.style.backgroundColor = 'black'; + volunteerTextColor.style.color = 'white'; } - // Making changes when clicking orange button.*/ var orangeButton = document.querySelector('#orangeBtn'); orangeButton.addEventListener('click', changetoOrange); +/*changetoOrange function. box, donateButton,volunteerButton's +background color changed.*/ function changetoOrange() { box.style.backgroundColor = '#f0ad4e'; donateButton.style.backgroundColor = '#5751fd'; volunteerButton.style.backgroundColor = '#31b0d5'; } - // Making changes when clicking green button. var greenButton = document.querySelector('#greenBtn'); greenButton.addEventListener('click', changeToGreen); +/* changeToGreen function.box, donateButton,volunteerButton's +background color changed. */ function changeToGreen() { box.style.backgroundColor = '#87ca8a'; donateButton.style.backgroundColor = 'black'; volunteerButton.style.backgroundColor = '#8c9c08'; } -/* Selecting the submit button and validating the form. -doesn't seem to be working.*/ -var submitButtom = document.querySelector('#submitButton'); -submitButtom.addEventListener('click', validateTheForm); +/* Selecting the submit button and creating "validateTheForm" function.*/ +var submitButton = document.querySelector('#submitButton'); +submitButton.addEventListener('click', validateTheForm); + +// This is ValidatTheForm function. used event.preventDefault() method. +function validateTheForm(event) { + event.preventDefault(); + + // selecting namebox with document.querySelector. + var namebox = document.querySelector('#example-text-input'); + // Adding value in namebox. + var nameboxWV = namebox.value; -function validateTheForm() { + // selecting email input box with document.querySelector. + var emailInput = document.querySelector('#exampleInputEmail1'); + // Adding value in emailInput. + var emailInputWV = emailInput.value; - var nameboxTag = document.querySelector(#example - text - input); - var namebox = document.querySelector('#example-text-input').value; - if (namebox.length === 0) { - nameboxTag.style.backgroundColor = '#8c9c08'; + // selecting describe yourself box with document.querySelector. + var describeYourselfInput = document.querySelector('#exampleTextarea'); + // Adding value in emailInput. + var describeYourselfInputWV = describeYourselfInput.value; + + // 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 + by assinging .className "inValid". Changing formIsValid from true to false.*/ + if (nameboxWV.length === 0) { + namebox.className = 'form-control inValid'; + formIsValid = false; } -} + + /* if the emailInput with value.length is invalid, changed background color of box to red + by assinging .className "inValid". Changing formIsValid from true to false.*/ + if (emailInputWV.length === 0 || emailInputWV.indexOf('@') === -1) { + emailInput.className = 'form-control inValid'; + formIsValid = false; + } + /* if the describeYourselfInput with value.length is invalid, changed background color of box to red + by assinging .className "inValid". Changing formIsValid from true to false.*/ + if (describeYourselfInputWV.length === 0) { + describeYourselfInput.className = 'form-control inValid'; + formIsValid = false; + } + + /* if the form is valid, alert (" thanks "), change namebox, describeYourself + and email's value to empty string value.*/ + if (formIsValid) { + alert("Thank you for filling out the form"); + namebox.value = ""; + describeYourselfInput.value = ""; + emailInput.value = ""; + } + + + + + diff --git a/js/main.js b/js/main.js index 57294c6..e52f334 100644 --- a/js/main.js +++ b/js/main.js @@ -57,10 +57,10 @@ var myButton = document.querySelector("#donateBike"); myButton.addEventListener("click", doSomething); function doSomething() { - var box = document.querySelector(".jumbotron"); - if (!box.className.includes("red")) { - box.className += " yellow"; - } + var box = document.querySelector(".jumbotron"); + if (!box.className.includes("red")) { + box.className += " yellow"; + } } diff --git a/styles/homeworkStyle.css b/styles/homeworkStyle.css new file mode 100644 index 0000000..a9636d4 --- /dev/null +++ b/styles/homeworkStyle.css @@ -0,0 +1,7 @@ +.volunteerText { + color: black; +} + +.inValid { + background-color:red; +} \ No newline at end of file From 6ce6ef5b41acfb4c64f27a225a53ef4a126ab9d6 Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Mon, 19 Jun 2017 22:15:29 +0100 Subject: [PATCH 6/7] Corrected all. --- js/homework.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/homework.js b/js/homework.js index 8baae98..58f342b 100644 --- a/js/homework.js +++ b/js/homework.js @@ -98,7 +98,7 @@ function validateTheForm(event) { emailInput.value = ""; } - +} From 721dee84141b426e9b2c0873fcf9cea7ad5da177 Mon Sep 17 00:00:00 2001 From: Won Maung Thein Date: Wed, 21 Jun 2017 14:12:28 +0100 Subject: [PATCH 7/7] made some homework, did some changes --- homework.html | 1 - js/homework.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/homework.html b/homework.html index b5e03dc..39635ca 100644 --- a/homework.html +++ b/homework.html @@ -3,7 +3,6 @@ Bikes for Refugees | Scotland - diff --git a/js/homework.js b/js/homework.js index 58f342b..c3dab44 100644 --- a/js/homework.js +++ b/js/homework.js @@ -48,7 +48,7 @@ function changeToGreen() { var submitButton = document.querySelector('#submitButton'); submitButton.addEventListener('click', validateTheForm); -// This is ValidatTheForm function. used event.preventDefault() method. +// This is ValidateTheForm function. used event.preventDefault() method. function validateTheForm(event) { event.preventDefault();