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

Javascript/week3/adebola #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions Week-3/.old/InClass/A-promises/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
Promise"
*/
function exercise1() {
var promise1 = resolvedPromise()
var promise1 = resolvedPromise();
return promise1;

}

exercise1().then(values => {
let result = document.getElementById("exercise1");
result.textContent = values;
return;
});

/*
EXERCISE 2
=======
Expand All @@ -28,8 +36,14 @@ function exercise1() {
*/
function exercise2() {
var promise2 = rejectedPromise()
return promise2;
}

exercise2().then().catch(values => {
let result = document.getElementById("exercise2");
result.textContent = values;
console.log(result);
return;
});
/*
EXERCISE 3
=======
Expand All @@ -40,8 +54,14 @@ function exercise2() {
EXPECTED RESULT: The #exercise3 element has textContent = "A Longer Promise"
*/
function exercise3() {
var promise3 = delayedPromise()
var promise3 = delayedPromise();
return promise3;
}
exercise3().then(values => {
let result = document.getElementById("exercise3");
result.textContent = values;
return;
});

/*
EXERCISE 4
Expand All @@ -55,9 +75,14 @@ function exercise3() {
YOUR NAME"
*/
function exercise4() {
var promise4 = concatPromise()
var promise4 = concatPromise();
return promise4;
}

exercise4().then(values => {
let result = document.getElementById("exercise4");
result.textContent = values.concat("Adebola");
return;
});
/*
EXERCISE 5 (Stretch Goal)
=======
Expand All @@ -70,10 +95,19 @@ function exercise4() {

EXPECTED RESULT: The #exercise5 element has textContent = "Hello Promises!"
*/

let myPromise = new Promise(function(resolve){
resolve("Hello Promises!");
})
function exercise5() {
let res = myPromise
return res;
// Write your implementation here
}
exercise5().then(values => {
let result = document.getElementById("exercise5");
result.textContent = values;
return;
});

/*
EXERCISE 6 (Stretch Goal)
Expand All @@ -88,9 +122,20 @@ function exercise5() {
EXPECTED RESULT: The #exercise6 element has textContent = "Something went
wrong!"
*/

let justPromised = new Promise(function(reject){
reject("Something went wrong!");
})
function exercise6() {
let worstExpectation = justPromised;
return worstExpectation;
// Write your implementation here
}
exercise6().then(values => {
let result = document.getElementById("exercise6");
result.textContent = values;
return;
});


//
Expand Down
8 changes: 7 additions & 1 deletion Week-3/.old/InClass/B-callbacks/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
document.querySelector('#button1').addEventListener('click', exercise1)

function exercise1() {
let exercise1 = document.getElementById("exercise1");
exercise1.textContent = "Adebola";
// Write your implementation here
}

Expand All @@ -37,6 +39,8 @@ function exercise1() {
functionThatCallsBack(exercise2)

function exercise2(result) {
let text = document.getElementById("exercise2");
text.textContent = "Hello from the function caller";
// Write your implementation here
}

Expand All @@ -57,11 +61,13 @@ function exercise2(result) {
*/

function exercise3(callback) {
callback("Hello from the callback");
// Write your implementation here

// Write your explanation here
// This callback is already a defined function and it is now used as a parameter
// in exercise3 function and also called in it
}

//
// -------------------------------------
//
Expand Down
10 changes: 8 additions & 2 deletions Week-3/.old/InClass/C-fetch/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ 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) {
let greet = document.getElementById("greeting-text")
console.log(greeting);
greet.innerHTML = greeting;
return;

// Write the code to display the greeting text here
});
});

13 changes: 9 additions & 4 deletions Week-3/.old/InClass/D-remote-clipboard/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Also, for GET request, you can use the url directly in your browser address bar
var clipboardTitle = "CHANGE ME";
var clipboardText = "CHANGE ME";
var requestBody = { title: clipboardTitle, text: clipboardText };

var url = `https://codeyourfuture.herokuapp.com/api/clipboard?title=myClipboardId`;
var postRequestParameters = {
body: JSON.stringify(requestBody),
method: 'POST',
Expand All @@ -32,12 +32,17 @@ var postRequestParameters = {
}
};

fetch(/* Write the API address here */, postRequestParameters);
fetch(url, postRequestParameters);


// Task 2: Load an existing clipboard
// Add your code below

fetch(/* ... */).then(function(response) {
fetch(url).then(function(response) {
return response.text();
}).then(/* ... */);
}).then(function(data){
let myData = document.getElementById("greeting-text");
console.log(data);
myData.innerText = data;
return;
});
11 changes: 10 additions & 1 deletion Week-3/.old/InClass/E-webchat/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ When you open index.html in your browser, it should display the existing message
*/


// Write your code here
// Write your code here
let url = `https://codeyourfuture.herokuapp.com/api/messages`;
fetch(url).then(function(response) {
return response.text();
}).then(function(message){
let myMessage = document.getElementById("message-list");
console.log(message);
myMessage.innerText = message;
return;
})
21 changes: 21 additions & 0 deletions Week-3/.old/InClass/E-webchat/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@ on the submit button. Then check the following:


// Write your code here
// document.getElementById("submit").addEventListener("click", submit);
// function submit(){
// let url = `https://codeyourfuture.herokuapp.com/api/messages`;
// fetch(url).then(function(response) {
// return response.text();
// }).then(function(message){
// let myMessage = document.getElementById("message-list").value;
// console.log(message);
// myMessage.innerText = message.;
// console.log(myMessage);
// return;

// })
// }

let myObj ={
name: "Ade",
Age: 37
}
localStorage.setItem("myObj", myObj);
console.log(localStorage);
24 changes: 22 additions & 2 deletions Week-3/Homework/mandatory/1-alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
function setAlarm() {}
function setAlarm() {
let alarmSet = document.getElementById("alarmSet");
remainingTime = document.getElementById("timeRemaining");
let time = parseInt(alarmSet.value);

let timeIn = setInterval(function(){
let min = Math.floor(time/60);
let sec = time-min * 60;

remainingTime.textContent = ("Time Remaining: ") + (min>9?min:"0" +min) + ":" + (sec>9?sec:"0" + sec);

if(time === 0){
playAlarm();

return clearInterval(timeIn);

}
time--;
}, 1000);

}

// DO NOT EDIT BELOW HERE

Expand All @@ -17,7 +37,7 @@ function setup() {
function playAlarm() {
audio.play();
}

function pauseAlarm() {
audio.pause();
}
Expand Down
1 change: 0 additions & 1 deletion Week-3/Homework/mandatory/1-alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
Expand Down
11 changes: 10 additions & 1 deletion Week-3/Homework/mandatory/2-quotegenerator/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<!DOCTYPE html>
<html>
<head>

<title>Quote Generator</title>
<script src="quotes.js"></script>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,900;1,300;1,500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="quote-box">
<p class="quote">I can do all things through christ</p>
<p class="author">Paul<span class="citation">Philippians 4:13</span></p>
</div>
<button id="myButton">Get Quotes</button>
</div>
<script src="quotes.js"></script>
<!-- Write your HTML in here -->

</body>
</html>
Loading