Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
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
25 changes: 14 additions & 11 deletions week-1/Homework/mandatory/1-debugging-practice/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ function submit() {
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
pages.value == "" ||
// added this to ensure author field must be provided //
author.value == null ||
author.value == ""
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book);
render();
}
}
Expand All @@ -54,7 +57,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -77,9 +80,9 @@ function render() {
cell4.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
} else {
readStatus = "Yes";
}
changeBut.innerHTML = readStatus;

Expand All @@ -90,11 +93,11 @@ function render() {

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
cell5.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
cell5.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
36 changes: 36 additions & 0 deletions week-2/Homework/mandatory/1-practice/1-practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,43 @@ The following endpoint is publicly available from Github
1. What would you put in the following fields? `{owner}`, `{repo}`, `{pull_number}`?

<!-- Write your answer here -->
For example: https://github.com/CodeYourFuture/JavaScript-Core-3-Homework/pull/19

The referenced link above is my Pull Request on Week 1 Homework I submitted on GitHub.
{owner} is CodeYourFuture
{repo} is JavaScript-Core-3-Homework
{pull_number} is 19 which is my PR Number on the repo

Similarly, GET https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/comments is a obtained by a GET request to the API on Github.
{owner} is the path that holds the individual, organisation or company that owns the API.

{repo} is the path that holds the particular repo where the API is stored on GitHub account.

{pull_number} is the particular #number of the pull request with the repo that the GET action refers to.

2. Describe in a sentence what this API endpoint returns when all of the fields are completed?

<!-- Write your answer here -->
The API endpoint has information about the GET request including the code status as below;
status: 200 OK.

Below is an example of what it will look like:

curl -i https://api.github.com/users/octocat/orgs
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 12 Oct 2012 23:33:14 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 200 OK
ETag: "a00049ba79152d03380c34652f2cb612"
X-GitHub-Media-Type: github.v3
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4987
X-RateLimit-Reset: 1350085394
Content-Length: 5
Cache-Control: max-age=0, private, must-revalidate
X-Content-Type-Options: nosniff


Reference: https://developer.github.com/v3/
17 changes: 11 additions & 6 deletions week-2/Homework/mandatory/2-fetch-exercise/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ 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 ***')
.then(function(response) {
return response.text();

fetch("https://codeyourfuture.herokuapp.com/api/greetings")
.then((response) => response.text())

.then ((data) => {
// Write the code to display the greeting text here
console.log(data)
let greetingMsg = document.getElementById("greeting-text")
greetingMsg.innerHTML = data
})
.then(function(greeting) {
// Write the code to display the greeting text here
});
.catch(error => console.log(error));

14 changes: 14 additions & 0 deletions week-2/Homework/mandatory/3-dog-photo-gallery/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<head>
<meta charset="utf-8" />
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Random Dog Photo Gallery</title>
</head>

<body>
<img id="dog-photo" src="https://images.dog.ceo/breeds/terrier-wheaten/n02098105_403.jpg" />
<button class="btn-element">Button</button>
<ul id="ul-element"></ul>
<script src="script.js"></script>
</body>

</html>
28 changes: 28 additions & 0 deletions week-2/Homework/mandatory/3-dog-photo-gallery/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function makeRandomPhoto(photo) {
const randomizedPhoto = Math.floor(Math.random() * randomPhoto.message);
photo = randomizedPhoto;
return photo;
}
let btnElem = document.querySelector(".btn-element");
//console.log(btnElem);
btnElem.addEventListener("click", () => {
fetch("https://dog.ceo/api/breeds/image/random")
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
const ulElem = document.getElementById("ul-element");
const liElem = document.createElement("li");
const imgElem = document.createElement("img");
imgElem.src = `${data.message}`;
liElem.appendChild(imgElem);
ulElem.appendChild(liElem);

})
.catch((error) => {
return `No photos ${error}`;
});
});

14 changes: 14 additions & 0 deletions week-2/Homework/mandatory/4-programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="divElem">
</div>
<script src="script.js"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions week-2/Homework/mandatory/4-programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Appended img with only JS codes
fetch(`https://xkcd.now.sh/?comic=latest`)
.then((response) => response.json())
.then((data) => {
console.log(data);
const imgElem = document.createElement("img");
const body = document.getElementsByName("BODY");
imgElem.src = `${data.img}`;
document.body.appendChild(imgElem);
})
.catch((error) => {
console.log(error);
});

// alternative option using HTML code to create a divElem first and create + append the img divElem //
fetch(`https://xkcd.now.sh/?comic=latest`)
.then((response) => response.json())
.then((data) => {
console.log(data);
const divElem = document.querySelector("#divElem")
const imgElem = document.createElement("img");
imgElem.src = `${data.img}`;
divElem.appendChild(imgElem);
})
.catch((error) => {
console.log(error);
});


Empty file.
11 changes: 11 additions & 0 deletions week-3/Homework/mandatory/2-exercises/1-shopping-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ The output of running your code should be:

class ShoppingCart {
// Add your code here
constructor() {
this.items = [];
}

addItem(el) {
this.items.push(el);
}

cartContains() {
const shoppingBasket = this.items;
console.log(`Your shopping cart has ${this.items.length} items: ${shoppingBasket}`)
// Use console.log() to output everything contained in your cart
}

}


let myCart = new ShoppingCart(); // Creates an empty shopping cart

Expand Down
10 changes: 10 additions & 0 deletions week-3/Homework/mandatory/2-exercises/2-convertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
*/

// Write your code here
class Person {
constructor(name) {
this.name = name;
}

greeting() {
const { name } = this;
console.log(`Hi! I'm ${this.name}.`);
}
}

// Do not edit this section
const simon = new Person("simon");
Expand Down
29 changes: 29 additions & 0 deletions week-3/Homework/mandatory/2-exercises/3-atm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,38 @@

class ATM {
// Add your code here
constructor(balance) {
balance = 100.0;
this.balance = balance;
console.log(this.balance);
}

make_deposit(p) {
const {
balance
} = this;
this.balance = this.balance + p;
console.log(this.balance);
}

check_balance() {
const {
balance
} = this;
console.log(this.balance);
}

make_withdrawl(m) {
const {
balance
} = this;
this.balance = this.balance - m;
console.log(this.balance);
}

}


let atm = new ATM(); // Create the ATM

atm.make_deposit(200);
Expand Down
55 changes: 46 additions & 9 deletions week-3/Homework/mandatory/2-exercises/4-music-player.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
class MusicPlayer {
// Add your code here

constructor(song, artist) {
const musicList = [];
this.song = song;
this.artist = artist;

}

add({
song,
artist
}) {
const {
list
} = this;
const totalList = musicList.push({
song
}, {
artist
});
console.log(totalList);
}

play() {
const {
song,
artist
} = this;
console.log(`Currently playing: ${this.song} by ${this.artist}`);
}

skip() {
const {
song,
artist
} = this;
console.log(`Currently playing: ${this.song} by ${this.artist}`);
}

previous() {
const {
song,
artist
} = this;
console.log(`Currently playing: ${this.song} by ${this.artist}`);
}
}


let myMusicPlayer = new MusicPlayer(); // Create an empty playlist

// Add some songs to your playlist
Expand Down Expand Up @@ -40,11 +85,3 @@ Optional 2: Can you implement the shuffle functionality for your music player?
This means the order the songs are played in will be random, but each song will only play once.

*/