Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Javscript core 3 h/w/adebola #51

Open
wants to merge 4 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
18 changes: 9 additions & 9 deletions week-1/Homework/mandatory/1-debugging-practice/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function submit() {
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 +54,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 @@ -76,7 +76,7 @@ function render() {
changeBut.className = "btn btn-success";
cell4.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check == true) {
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -90,11 +90,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
6 changes: 4 additions & 2 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,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) {
// Write the code to display the greeting text here
});
let pEl = document.getElementById("greeting-text");
pEl.innerHTML = greeting;
}).catch(error => console.log(error));
50 changes: 50 additions & 0 deletions week-2/Homework/mandatory/3-dog-photo-gallery/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
let submit = document.getElementById("my-button");
submit.addEventListener("click", function(){
fetch("https://dog.ceo/api/breeds/image/random")

.then(function(response){
return response.json();
})
.then(function(data){
let ul = document.createElement("ul");

let list = document.createElement("li");

let image = document.createElement("img");

image.src = data.message;

list.appendChild(image);

document.body.appendChild(list);
image.style.width = "100%"
list.style.listStyle = "none";
list.style.display = "flex";
list.style.justifyContent = "center";
list.style.margin ="10px";
list.style.width = "40%";

var del = document.createElement('button');
del.style.textDecoration = 'none';
del.innerHTML = 'Remove this?';
del.style.color = 'white';
del.style.backgroundColor = '#3CAEA3';
//assign a function for it when clicked
del.onclick = function() { deleteButton(list,this)};
document.body.appendChild(del)

})
})

.catch(function (error){
console.log(error);
});
function deleteButton(x,y) {

var parent = document.getElementsByTagName("BODY")[0];
//remove the list
parent.removeChild(x);
//remove the button
parent.removeChild(y);

}
13 changes: 13 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,13 @@
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dog Photo Gallery</title>
</head>
<body>
<button id="my-button">Please Click for display</button>
<script src="exercise.js"></script>
</body>
</html>
12 changes: 12 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,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<title>Document</title>
</head>
<body>
<script src="script.js" ></script>
</body>
</html>
5 changes: 5 additions & 0 deletions week-2/Homework/mandatory/4-programmer-humour/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.container{
display: flex;
justify-content: center;
padding-top: 150px;
}
26 changes: 26 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,26 @@
fetch("https://xkcd.now.sh/?comic=latest")
.then(function(response){
return response.json();
})
.then(function(data){
console.log(data.img);
let ul = document.createElement("ul");
let li = document.createElement("li");
let img = document.createElement("img");
li.appendChild(img);
ul.className = "container"
ul.style.display = "flex"
ul.style.margin = "0 auto"
ul.style.width ="150px"
li.style.listStyleType = "none";
document.body.style.backgroundColor = "silver"
img.className = "image"
img.src = data.img;
ul.appendChild(li)
console.log(ul)
document.body.appendChild(ul)
})
.catch(function (error){

console.log(error);
});
27 changes: 27 additions & 0 deletions week-3/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<link rel="stylesheet" href="weather.css">
<title>Weather</title>
</head>
<body>
<div class="location">
<h1 class="location-timezone">Timezone</h1>
<canvas class="icon" width="128" height="128"></canvas>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temperature-degree">34</h2>
<span>F</span>
</div>

<div class="temperature-description">Its cold</div>
</div>
<script src="weather.js"></script>
<script src="skycons.js"></script>
</body>
</html>
Loading