Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
# dotenv environment letiables file
.env

.netlify
Expand Down
1 change: 1 addition & 0 deletions Week1/exercise/w1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<body>
<h1>Hack your future</h1>
<button id="change-header">Change Header</button>
<h2>JS2 - exercise 1</h2>

<div>
Expand Down
48 changes: 41 additions & 7 deletions Week1/exercise/w1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ console.log('Hack your future Belgium!');
// 1b: inside this function: select the header element and assign that to a variable called "header"

// 1c: change the inner html of the header element to your name


// Answer Exercise 1
//=============================//
// function
function changeHeader(){
console.log('hello');
let header = document.querySelector('h1');
header.innerHTML = 'Berihu';
}
// Event listener
let change_button = document.getElementById('change-header');
change_button.addEventListener('click',changeHeader);
// ====================================== //


// EXERCISE 2

// 2a: create a function called "changeImage", put a console.log() inside this function to test
Expand All @@ -28,11 +36,18 @@ console.log('Hack your future Belgium!');
// 2d: select the image element and assign to a variable called "imageToChange"

// 2e: to change the image: assign the imageInputValue to the image src


// Answer to exercise -2
//==================================//
//function
function changeImage(){
let imageInputValue = document.getElementById('imageInput').value;
let imageToChange = document.getElementById('imageToChange');
imageToChange.src = imageInputValue;
}
// Event Listener
let change_image_button = document.getElementById('btn-changeImage');
change_image_button.addEventListener('click',changeImage);
// ====================================== //


// Exercise 3:

// 3a: select "add todo" button & add click event listener to execute addTodo() function on click event
Expand All @@ -48,3 +63,22 @@ console.log('Hack your future Belgium!');
// 3f: set created <li> element innerHtml to todoInput value

// 3g: add <li> element to todoList
//================================================//
//Answer to exercise 3
//Event Listener
let add_todo_button = document.getElementById('btn-addTodo');
add_todo_button.addEventListener('click',addTodo);

//function
function addTodo(){
let list = document.getElementById('todoList');
let new_list= document.createElement('li');
let item_text = document.getElementById('todoInput').value;
let list_text = document.createTextNode(item_text);
new_list.appendChild(list_text);
if(item_text ===''){// if input value is empty
alert('please add some item')
} else {
list.appendChild(new_list);// adding created 'li' element to 'ul'
}
}
37 changes: 37 additions & 0 deletions Week1/homework/FCC-Intermediate Algorithm Scripting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Intermediate Algorithm Scripting
## 1. Sum All Numbers in a Range
```js
function sumAll(arr) {
let upper = Math.max(arr[0],arr[1]);
let lower = Math.min(arr[0],arr[1]);
let list = [];
let total = 0;
for(let i = lower; i <= upper;i++){
list.push(i);
total= total + i;
}
return total;
}

sumAll([-1, 4]);
```
## 2. Diff Two Arrays
```js
function diffArray(arr1, arr2) {
var newArr = [];
function onlyInFirst(first, second) {
// Looping through an array to find elements that don't exist in another array
for (var i=0;i<first.length;i++) {
if (second.indexOf(first[i]) === -1) {
// Pushing the elements unique to first to newArr
newArr.push(first[i]);
}
}
}
onlyInFirst(arr1, arr2);
onlyInFirst(arr2, arr1);

return newArr;
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
```
Loading