Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ Call the function three times. The return values should be:

*/

function createBase( /* ???? */ ) {
function createBase(num) {
// Put here your logic...
function add(num) {
return num + 9;
}
return add;
}

const addSix = createBase(6);

console.log(addSix(6));
console.log(addSix(15));
console.log(addSix(24));
// Put here your function calls...

19 changes: 19 additions & 0 deletions 19 Week3/Masoud/js-exercises/ex2-RemoveDuplicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const letters = ['a', 'b', 'b', 'c', 'd', 'a', 'e', 'f', 'f', 'c', 'b'];
const nonDuplicates = [];

function removeDuplicates(array) {
nonDuplicates.push(array[0]);
for (let i = 1; i < array.length; i++) {
const x = [];
for (let j = 0; j < i; j++) {
if (array[j] == array[i]) {
x.push(array[j]);
}
}
if (x.length == 0) {
nonDuplicates.push(array[i]);
}
}
return nonDuplicates;
}
console.log(removeDuplicates(letters));
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ const x = (function () {
};
})();

x();
x();

//Output is alert to brower number 12, change the value of a to 12 because a declares as a global variable.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function f1(val) {
return val;
}
f1(x);
console.log(x);
console.log(f1(x));

const y = {
x: 9
Expand All @@ -26,4 +26,6 @@ function f2(val) {
return val;
}
f2(y);
console.log(y);
console.log(f2(y));

// In this example, x has 2 parts, one of them is varible and the other is property of object y
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,41 @@ Don't you just love the thrill of the lottery? What if I told you we can make ou
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
const numbers = [];
// make array
if (startIndex > stopIndex) {
console.log('Change the values: The stop number should be greater than start number')
} else {
let pointer = startIndex;
for (let i = 0; i < stopIndex - startIndex + 1; i++) {
numbers.push(pointer);
pointer++;
}
}
// start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next
numbers.forEach(function (arr) {
if (arr % 3 == 0 && arr % 5 == 0) {
threeCallback(arr);
fiveCallback(arr);
} else if (arr % 5 == 0) {
fiveCallback(arr);
} else if (arr % 3 == 0) {
threeCallback(arr);
} else {
console.log('number ' + arr + ' is not divisible by 3 or 5');
}
})


}

threeFive(10, 15, sayThree, sayFive);
threeFive(1, 10, sayThree, sayFive);

// Should create an array [10,11,12,13,14,15]
// and call sayFive, sayThree, sayThree, sayFive
// and call sayFive, sayThree, sayThree, sayFive

function sayThree(arr) {
console.log('Number ' + arr + ' is divisible by 3');
}

function sayFive(arr) {
console.log('Number ' + arr + ' is divisible by 5');
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions 57 Week3/Masoud/project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div id="app">
<h1>Tip Calculator</h1>
<hr>
<form id="form">
<label for="bill">How much was youl bill?</label>
<input type="number" min='0' id="bill">

<label for="service">How was you service?</label>
<select id="service">
<option value="default" disabled selected>--Choose an option--</option>
<option value="30">30% - Outstanding</option>
<option value="20">20% - Good</option>
<option value="15">15% - It was OK</option>
<option value="10">10% - Bad</option>
<option value="5">5% - Terrible</option>
</select>

<label for="people">How many people are shating the bill?</label>
<input type="number" min='0' id="people">

<button id="calculate">Calculate!</button>
</form>

<div class="amount">
<h2>TIP AMOUNT</h2>
<span id="amount">-</span>
<span id="each">-</span>
</div>

<div class="clearfix"></div>

<div id="modal" class="trans modal">
<div class="modal-box">
<h3>Warning</h3>
<p>Please fill all fields</p>
<button id="close">close</button>
</div>
</div>

</div>


<script src="index.js"></script>
</body>

</html>
41 changes: 41 additions & 0 deletions 41 Week3/Masoud/project/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//declare variables
const bill = document.getElementById('bill');
const service = document.getElementById('service');
const people = document.getElementById('people');
const calculate = document.getElementById('calculate');
const amount = document.getElementById('amount');
const each = document.getElementById('each');
const modal = document.getElementById('modal');
const close = document.getElementById('close');

// When press on calculate button
calculate.addEventListener('click', calculateTip);

//calculate tip
function calculateTip(e) {
e.preventDefault();

// Display modal element when at least one field empty
if (bill.value == '' || service.value == 'default' || people.value == '') {
modal.style.display = 'block';
close.addEventListener('click', function () {
modal.style.display = 'none';
clearTimeout(timing);
});
const timing = setTimeout(function () {
modal.style.display = 'none';
}, 5000);
//transition modal
modal.classList.remove('trans');
setTimeout(function () {
modal.classList.add('trans');
}, 5);
} else { //Calculate tip when all fields are filled
amount.textContent = parseFloat(service.value * bill.value / 100 / people.value).toFixed(2);
each.textContent = 'each';
each.style.display = 'block';
if (people.value == 1) {
each.style.display = 'none';
}
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.