Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Week3 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 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
70 changes: 62 additions & 8 deletions Week1/homework/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
'use strict';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an extra space here. In fact, I think there looks like to be lots of strange spacing. Can you run prettier on your files so they fix the formatting issues?

{
const bookTitles = [
// Replace with your own book titles
'harry_potter_chamber_secrets',
];
'use strict'
const books = [
{
title :"Harry Potter Chamber of Secrets",
language:"english",
author:"Joanne K. Rowling",

// Replace with your own code
console.log(bookTitles);
},

{
title:"Alchemist",
language:"english",
author:"paulo-co",

},

{
title:"Paula",
language:"english",
author:"isabel allende",

},

{

title:"Orlando",
language:"english",
author:"virginia-wolf",

},

{
title:"Divine Comedy",
language:"English",
author:"dante",

},

{
title:"The Odyssey",
language: "english",
author:"Homeros",

},

]

function createAndAppend(parent,typ,attributes={}) {

const elem = document.createElement(typ)

parent.appendChild(elem)

for (const key in attributes)

elem[key] = attributes[key]
return elem
}

const ul = createAndAppend(document.body, 'ul', {})
for (const index in books) {
const book = books[index]
createAndAppend(ul, 'li', {value : index, innerHTML: book.title})
}
11 changes: 10 additions & 1 deletion Week1/homework/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<!-- replace this with your HTML content -->
<!DOCTYPE html>
<html>
<head>
<title> Book Titles</title>

</head>
<body>
<script src="app.js"></script>
</body>
</html>
Binary file added Week1/homework/odyssy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week1/homework/paula.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week1/homework/potter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week1/homework/woolf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion Week2/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
</head>
<body>
<h3>Here is your advice for the day:</h3>
<h1 id="advice"></h1>
<ul id="advice"></ul>
<button id="add-advice">add one more </button>
<script type="text/javascript" src="./lecture-exercises.js"></script>
</body>
</html>
27 changes: 26 additions & 1 deletion Week2/homework/map-filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
/*'use strict';

function doubleOddNumbers(numbers) {
// Replace this comment and the next line with your code
Expand All @@ -12,4 +12,29 @@ console.log(doubleOddNumbers(myNumbers));
module.exports = {
myNumbers,
doubleOddNumbers,
}; */

'use strict';

function doubleOddNumbers(numbers) {

numbers = numbers.filter(num => num % 2 === 1).map(num => num * 2);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! But there seems to be many blank lines above and below. Can you delete?


console.log(numbers);

return numbers;



const myNumbers = [1, 2, 3, 4];

console.log(doubleOddNumbers(myNumbers));
module.exports = {

myNumbers,

doubleOddNumbers,

};

//finished
133 changes: 133 additions & 0 deletions Week2/homework/week2maartjes-work.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange spacing in this file too. Too many blank lines. Needs Prettier formatting.

'use strict';



const monday = [

{

name: 'Write a summary HTML/CSS',

duration: 180,

},

{

name: 'Some web development',

duration: 120,

},

{

name: 'Fix homework for class10',

duration: 20,

},

{

name: 'Talk to a lot of people',

duration: 200,

},

];



const tuesday = [

{

name: 'Keep writing summary',

duration: 240,

},

{

name: 'Some more web development',

duration: 180,

},

{

name: 'Staring out the window',

duration: 10,

},

{

name: 'Talk to a lot of people',

duration: 200,

},

{

name: 'Look at application assignments new students',

duration: 40,

},

];



const maartjesTasks = monday.concat(tuesday);

const maartjesHourlyRate = 20;



function computeEarnings(tasks, hourlyRate) {

const inHoursArr = tasks.map(task => task.duration / 60).filter(hours => hours <= 2);

const maartjesPayArr = inHoursArr.map(hours => hours * maartjesHourlyRate);

const totalPay = maartjesPayArr.reduce((sum, amount) => sum + amount);

const toEuro = totalPay.toFixed(2);

return toEuro;

}





const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);



//converting



console.log(`Martje has earned €${earnings}`);


module.exports = {

maartjesTasks,

maartjesHourlyRate,

computeEarnings,

};
36 changes: 34 additions & 2 deletions Week2/lecture-exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,41 @@ async function getRandomAdvice() {
return adviceData.slip.advice;
}

let allAdvice=[]
const adviceEl = document.getElementById('advice');


function updateDOM() {
adviceEl.innerHTML= '';

allAdvice.forEach((advice, index)=> {


const adviceItem=document.createElement ('li')
adviceEl.appendChild(adviceItem);
adviceItem.innerText=advice;

const removeButton =document.createElement('button')
removeButton.innerText='remove';
adviceItem.appendChild(removeButton);
removeButton.addEventListener('click',() => deleteAdvice(index));_
})
}
function deleteAdvice (index){
allAdvice.splice(index,1);
updateDOM();
}
function upcaseAllAdvice (){
allAdvice=allAdvice.map(advice => advice.toUpperCase());
updateDOM();

async function setRandomAdvice() {
const adviceEl = document.getElementById('advice');
adviceEl.innerText = await getRandomAdvice();
allAdvice.push (await getRandomAdvice());
updateDOM();
}

setRandomAdvice();

document.getElementById('add-advice').addEventListener('click', setRandomAdvice);

document.getElementById('upcase-everything').addEventListener('click', upcaseAllAdvice);
11 changes: 3 additions & 8 deletions Week3/homework/step2-1.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
'use strict';

function foo(func) {
// What to do here?
// Replace this comment and the next line with your code
console.log(func);
func();
}

function bar() {
console.log('Hello, I am bar!');
}

foo(bar);

// Do not change or remove anything below this line
module.exports = foo;

//finished
42 changes: 31 additions & 11 deletions Week3/homework/step2-2.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
'use strict';

function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
{
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {

const numbers = [];
for (let i = startIndex; i <= stopIndex; i++) {

// Replace this comment and the next line with your code
console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers);
}
numbers.push(i);

//A callback to call if the number is divisible by 3

if (i % 3 === 0) {

threeCallback(i);

}

//A callback by 5

if (i % 5 === 0) {

fiveCallback(i);

}}}


threeFive()

function sayThree(number) {
// Replace this comment and the next line with your code
console.log(number);
console.log(number, 'value is divisible by 3');
}



function sayFive(number) {
// Replace this comment and the next line with your code
console.log(number);
console.log(number, 'value is divisible by 5');
}

threeFive(10, 15, sayThree, sayFive);

// Do not change or remove anything below this line
module.exports = threeFive;

}
//finished
Loading