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 ======= 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 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) +}); 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 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 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 @@ - -+ + + ++