From 951d78d76be8eca521999390019a78c1c34bf15b Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Wed, 29 Jul 2020 11:08:20 +0100 Subject: [PATCH 1/8] Started week 3 homework / fetch has done fetch completed --- Week-3/.old/InClass/C-fetch/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Week-3/.old/InClass/C-fetch/exercise.js b/Week-3/.old/InClass/C-fetch/exercise.js index fb3a39c..230f037 100644 --- a/Week-3/.old/InClass/C-fetch/exercise.js +++ b/Week-3/.old/InClass/C-fetch/exercise.js @@ -17,10 +17,12 @@ Open index.html in your browser. Every time you refresh the page, a different greeting should be displayed in the box. */ -fetch('*** Write the API address here ***') +fetch('https://codeyourfuture.herokuapp.com/api/greetings') .then(function(response) { return response.text(); }) .then(function(greeting) { + + document.querySelector('#greeting-text').innerHTML = greeting; // Write the code to display the greeting text here }); \ No newline at end of file From e7fd5e82f3b3e8b4d744ef6af99575546ede3895 Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Wed, 29 Jul 2020 11:56:14 +0100 Subject: [PATCH 2/8] .old/D/remote -clipboard has done remote clipboard completed --- Week-3/.old/InClass/D-remote-clipboard/exercise.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Week-3/.old/InClass/D-remote-clipboard/exercise.js b/Week-3/.old/InClass/D-remote-clipboard/exercise.js index d2d83f5..61142f1 100644 --- a/Week-3/.old/InClass/D-remote-clipboard/exercise.js +++ b/Week-3/.old/InClass/D-remote-clipboard/exercise.js @@ -20,8 +20,8 @@ Also, for GET request, you can use the url directly in your browser address bar // Task 1: create a new clipboard // Complete the code below -var clipboardTitle = "CHANGE ME"; -var clipboardText = "CHANGE ME"; +var clipboardTitle = "Birmingham"; +var clipboardText = "I am from Birminghammmm"; var requestBody = { title: clipboardTitle, text: clipboardText }; var postRequestParameters = { @@ -32,12 +32,14 @@ var postRequestParameters = { } }; -fetch(/* Write the API address here */, postRequestParameters); +fetch('https://codeyourfuture.herokuapp.com/api/clipboard', postRequestParameters); // Task 2: Load an existing clipboard // Add your code below -fetch(/* ... */).then(function(response) { +fetch('https://codeyourfuture.herokuapp.com/api/clipboard?title=Birmingham').then(function(response) { return response.text(); -}).then(/* ... */); +}).then(function(result){ + console.log(result) +}); From ab997264973056591c4147e95fcd935d0c61478f Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Wed, 29 Jul 2020 14:20:51 +0100 Subject: [PATCH 3/8] .old/InClass/E/webChat exercises done webchat completed --- Week-3/.old/InClass/E-webchat/exercise-1.js | 15 ++++++++++++- Week-3/.old/InClass/E-webchat/exercise-2.js | 25 +++++++++++++++++++++ Week-3/.old/InClass/E-webchat/exercise-3.js | 21 ++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Week-3/.old/InClass/E-webchat/exercise-1.js b/Week-3/.old/InClass/E-webchat/exercise-1.js index 0e86590..670020f 100644 --- a/Week-3/.old/InClass/E-webchat/exercise-1.js +++ b/Week-3/.old/InClass/E-webchat/exercise-1.js @@ -34,4 +34,17 @@ When you open index.html in your browser, it should display the existing message */ -// Write your code here \ No newline at end of file +// Write your code here +// fetch('https://codeyourfuture.herokuapp.com/api/messages') +// .then(function(response){ +// return response.json(); +// }) +// .then(function(messages){ +// //document.querySelector('#message-list').innerHTML =""; +// messages.forEach(function(message){ +// document.querySelector('#message-list').innerHTML+='
'+message.content +'
' +// // let newParagraph = document.createElement('p'); +// // newParagraph.innerText +// // document.querySelector('message-list').appendChild(newParagraph); +// }) +// }) \ No newline at end of file diff --git a/Week-3/.old/InClass/E-webchat/exercise-2.js b/Week-3/.old/InClass/E-webchat/exercise-2.js index f8a0d6f..12cfaeb 100644 --- a/Week-3/.old/InClass/E-webchat/exercise-2.js +++ b/Week-3/.old/InClass/E-webchat/exercise-2.js @@ -27,3 +27,28 @@ on the submit button. Then check the following: // Write your code here +var postRequestParameters = { + body: JSON.stringify({ "content":new Date() }), + method: 'POST', + headers: { + 'content-type': 'application/json' + } +}; + +fetch('https://codeyourfuture.herokuapp.com/api/messages',postRequestParameters); + +fetch('https://codeyourfuture.herokuapp.com/api/messages') +.then(function(response){ + return response.json(); +}) +.then(function(messages){ +//document.querySelector('#message-list').innerHTML =""; +document.querySelector('#message-list').innerHTML+=''+messages[messages.length-1].content +'
' + +// messages.forEach(function(message){ +// document.querySelector('#message-list').innerHTML+=''+message.content +'
' +// // let newParagraph = document.createElement('p'); +// // newParagraph.innerText +// // document.querySelector('message-list').appendChild(newParagraph); +// }) +}) \ No newline at end of file diff --git a/Week-3/.old/InClass/E-webchat/exercise-3.js b/Week-3/.old/InClass/E-webchat/exercise-3.js index cd551a4..39204df 100644 --- a/Week-3/.old/InClass/E-webchat/exercise-3.js +++ b/Week-3/.old/InClass/E-webchat/exercise-3.js @@ -33,7 +33,11 @@ For example, print your name every 2 seconds. // Write your code here +function callback() { + console.log("Mursel"); +} +setInterval(callback, 3000); /* ======== Task 4 @@ -42,4 +46,19 @@ Task 4 Use the setInterval function to reload automatically the messages of your webchat every 2 seconds. The code responsible to show the messages in the page is in exercise-1.js, so you will need to write your code there :-) */ - +function newPages(){ +fetch('https://codeyourfuture.herokuapp.com/api/messages') +.then(function(response){ + return response.json(); +}) +.then(function(messages){ +//document.querySelector('#message-list').innerHTML =""; +messages.forEach(function(message){ + document.querySelector('#message-list').innerHTML+=''+message.content +'
' +// let newParagraph = document.createElement('p'); +// newParagraph.innerText +// document.querySelector('message-list').appendChild(newParagraph); +}) +}) +} +setInterval(newPages,9000); \ No newline at end of file From 65f6b76128cecafe03c023fea7d4386be9bc5162 Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Sat, 1 Aug 2020 10:03:20 +0100 Subject: [PATCH 4/8] old/InClass callback done completed callback --- Week-3/.old/InClass/B-callbacks/exercise.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week-3/.old/InClass/B-callbacks/exercise.js b/Week-3/.old/InClass/B-callbacks/exercise.js index 3ba78e8..f46c000 100644 --- a/Week-3/.old/InClass/B-callbacks/exercise.js +++ b/Week-3/.old/InClass/B-callbacks/exercise.js @@ -14,12 +14,13 @@ EXPECTED RESULT: The #exercise1 element has textContent = "YOUR NAME" when the button is clicked */ -document.querySelector('#button1').addEventListener('click', exercise1) +document.querySelector('#button1').addEventListener('click', exercise1); +var textElement = document.querySelector('#button1'); function exercise1() { // Write your implementation here + textElement.textContent = "My Name"; } - /* EXERCISE 2 ======= From 21852dc0500512aa991a5cd0c929909c6aad30dc Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Sat, 1 Aug 2020 10:06:44 +0100 Subject: [PATCH 5/8] Mandatory Alarm Clock is done Alarm Clock --- .../mandatory/1-alarmclock/alarmclock.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js index 6ca81cd..ca44b09 100644 --- a/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js +++ b/Week-3/Homework/mandatory/1-alarmclock/alarmclock.js @@ -1,4 +1,35 @@ -function setAlarm() {} +function setAlarm() { + let inputTime = document.getElementById("alarmSet").value; + let timeRemaining = document.getElementById("timeRemaining"); + + function timeFormat(time) { + let allMinutes; + let seconds; + if (time > 60) { + allMinutes = Math.floor(time / 60); + seconds = time - allMinutes * 60; + } else { + allMinutes = 0; + seconds = time; + } + if (allMinutes < 10) { + allMinutes = "0" + allMinutes; + } + if (seconds < 10) { + seconds = "0" + seconds; + } + return `${allMinutes}:${seconds}`; + } + + let alarm = setInterval(() => { + if (inputTime === 0) { + playAlarm(); + clearInterval(alarm); + } + timeRemaining.textContent = `Time remaining: ${timeFormat(inputTime)}`; + inputTime--; + }, 1000); +} // DO NOT EDIT BELOW HERE From 93f43a42c92a9fc78a9c910c8ca02f9fc374da03 Mon Sep 17 00:00:00 2001 From: murselaysan <64005116+murselaysan@users.noreply.github.com> Date: Sat, 1 Aug 2020 10:44:34 +0100 Subject: [PATCH 6/8] Mandatory Quote Generator Done nearly done, --- .../mandatory/2-quotegenerator/index.html | 40 ++++++++++++------- .../mandatory/2-quotegenerator/quotes.js | 36 +++++++++++++++-- .../mandatory/2-quotegenerator/style.css | 17 ++++++++ 3 files changed, 74 insertions(+), 19 deletions(-) diff --git a/Week-3/Homework/mandatory/2-quotegenerator/index.html b/Week-3/Homework/mandatory/2-quotegenerator/index.html index b6115be..b155cb4 100644 --- a/Week-3/Homework/mandatory/2-quotegenerator/index.html +++ b/Week-3/Homework/mandatory/2-quotegenerator/index.html @@ -1,17 +1,27 @@ - -+ + + ++