Skip to content
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

add completed exercises #382

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f8fa350
01-Lecture 9 done
SeldonTselung May 11, 2023
adb3f78
lecture 11 complete
SeldonTselung May 11, 2023
c74a506
assignment
SeldonTselung May 12, 2023
cab8d01
assignments & challenge1
SeldonTselung May 16, 2023
ae072ec
finished coding challenge part 1
SeldonTselung May 17, 2023
360cd52
fundamentals part2
SeldonTselung May 18, 2023
2c8ced1
fundamentals part2
SeldonTselung May 18, 2023
3bae00e
finished coding challenge1
SeldonTselung May 18, 2023
4b3ee73
coding challenge 2
SeldonTselung May 18, 2023
8e90c18
completed challenges 3 & 4
SeldonTselung May 21, 2023
0271678
section 3 challenge completed
SeldonTselung May 22, 2023
d578d6b
completed section 5
SeldonTselung May 23, 2023
10de368
completed dry principle
SeldonTselung May 23, 2023
085aa7e
completed 06
SeldonTselung Jun 23, 2023
40afd42
game
SeldonTselung Jul 7, 2023
fbdb169
finished exercise 9
SeldonTselung Aug 14, 2023
e58ffc9
deleted random file, added section 9
SeldonTselung Aug 14, 2023
2fd65f3
section 9 challenge 2
SeldonTselung Aug 15, 2023
7945fe8
completed challenge 3
SeldonTselung Aug 15, 2023
3527433
completed challenge 4
SeldonTselung Aug 17, 2023
8465387
passing-arguments
SeldonTselung Aug 21, 2023
cff66b8
functions returning functions
SeldonTselung Aug 22, 2023
57cc792
added tax function
SeldonTselung Aug 22, 2023
2f80cb4
coding challenge 1
SeldonTselung Aug 22, 2023
f80b894
closures done
SeldonTselung Aug 22, 2023
c2c175b
coding challenge 2
SeldonTselung Aug 22, 2023
0e0a2a6
coding challenge 1 completed
SeldonTselung Aug 22, 2023
ad3b8ac
added all the movements
SeldonTselung Aug 22, 2023
f59bd99
added map
SeldonTselung Aug 22, 2023
9529801
added filter method ex
SeldonTselung Aug 22, 2023
6325475
finished reduce exercise
SeldonTselung Aug 22, 2023
29680ae
coding challenge 2
SeldonTselung Aug 23, 2023
5862a10
coding challenge 3
SeldonTselung Aug 23, 2023
c42b011
added login and displayed components
SeldonTselung Aug 23, 2023
d7d64d8
added transfers
SeldonTselung Aug 28, 2023
f28150c
added loan and acc close functionality
SeldonTselung Aug 29, 2023
6c21658
sort functionality added
SeldonTselung Aug 29, 2023
5519024
completed challenge 4
SeldonTselung Aug 29, 2023
5738be6
prototypal inheritance
SeldonTselung Aug 29, 2023
7149456
completed challenge 1-oop
SeldonTselung Aug 29, 2023
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
54 changes: 54 additions & 0 deletions 01-Fundamentals-Part-1/starter/assignments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Values and Variables

const country = "America";
const continent = "North America";
let population = 300;
console.log(country, continent, population);

// Data Types

const isIsland = false;
let language;
console.log(isIsland, population, country, language)

// let, const, var

language = "English";

// basic operators

let populationHalf = population / 2;
population = population + 1;

let populationFinland = 6;
const isPopulationGreaterThanFinland = population > populationFinland;
console.log(isPopulationGreaterThanFinland);

let populationAverage = 33;
const isPopulationLessThanAverage = population < populationAverage;
console.log(isPopulationLessThanAverage);

let description = country + " is in " + continent + " , and its " + population + " million people speak " + language

// String and Template literals

description = `${country} is in ${continent}, and its ${population} million people speak ${language}`

// if else

if (population > populationAverage) {
console.log(`${country}'s population is above average 👀`);
} else {
console.log(`${country}'s population is ${populationAverage - population} million below average`);
}

//type conversion and coercion

const inputYear = '1991';

console.log(Number(inputYear));

console.log(inputYear * 18);

//truthy and falsy
const aNumber = Number(window.prompt("Type a number", ""));
67 changes: 67 additions & 0 deletions 01-Fundamentals-Part-1/starter/coding_challenge_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Coding Challenge 1

const johnHeight_m = 1.95;
const johnMass_kg = 92;

const markHeight_m = 1.69;
const markMass_kg = 78;

const john_BMI = (johnMass_kg / johnHeight_m ** 2).toFixed(1);

const mark_BMI = (markMass_kg / markHeight_m ** 2).toFixed(1);

let markHigherBMI = mark_BMI > john_BMI;

console.log(john_BMI, mark_BMI, markHigherBMI);

const johnHeight2_m = 1.95;
const johnMass2_kg = 92;

const markHeight2_m = 1.69;
const markMass2_kg = 78;

const john2_BMI = (johnMass2_kg / johnHeight2_m ** 2).toFixed(1);

const mark2_BMI = (markMass2_kg / markHeight2_m ** 2).toFixed(1);

markHigherBMI = mark2_BMI > john2_BMI;

console.log(john2_BMI, mark2_BMI, markHigherBMI);

//Coding challenge 2

if (markHigherBMI) {
console.log(`Mark's BMI (${mark_BMI}) is higher than John's (${john_BMI})!`)
} else {
console.log(`John's BMI (${john_BMI}) is higher than Marks's (${mark_BMI})!`)
}

if (markHigherBMI) {
console.log(`Mark's BMI (${mark2_BMI}) is higher than John's (${john2_BMI})!`)
} else {
console.log(`John's BMI (${john2_BMI}) is higher than Marks's (${mark2_BMI})!`)
}

//coding challenge 3
const dolphinData1 = 96;
const dolphinData2 = 108;
const dolphinData3 = 89;
const koalaData1 = 88;
const koalaData2 = 91;
const koalaData3 = 110;

const dolphinAverage = (dolphinData1 + dolphinData2 + dolphinData3) / 3;
const koalaAverage = (koalaData1 + koalaData2 + koalaData3) / 3;

if (dolphinAverage > koalaAverage) {
console.log('Dolphins win the trophy');
} else {
console.log('Koalas win the trophy');
}

//coding challenge 4
const bill_$ = 275;

let tip = bill_$ >= 50 && bill_$ <= 300 ? (.15 * bill_$) : (.20 * bill_$);

console.log(`The bill was ${bill_$}, the tip was ${tip}, and the total value ${bill_$ + tip}`);
3 changes: 3 additions & 0 deletions 01-Fundamentals-Part-1/starter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
</head>
<body>
<h1>JavaScript Fundamentals – Part 1</h1>
<script src="script.js"></script>
<script src="assignments.js"></script>
<script src="coding_challenge_1.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions 01-Fundamentals-Part-1/starter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let js = 'amazing';
if (js === 'amazing') alert('JavaScript is FUN!');

console.log(40 + 8 + 23 - 10);
console.log("Jonas");
console.log(23);

let firstName = "Matilda";

console.log(typeof firstName);
console.log(firstName);

let jonas_matilda = "JM";
let $function = 27;

var stuff;
let thing;

console.log(10/0);

console.log(stuff);
console.log(thing);


let c = 2;
c **= 2;
console.log(c);
95 changes: 95 additions & 0 deletions 02-Fundamentals-Part-2/starter/coding_challenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict'
//coding challenge 1

const calcAverage = (score1, score2, score3) => (score1 + score2 + score3) / 3;

let avgKoalas = calcAverage(65, 54, 49);
let avgDolphins = calcAverage(44, 23, 71);

const checkWinner = (avgDolphins, avgKoalas) => {
if (avgDolphins >= 2 * avgKoalas) {
console.log(`Dolphins win (${avgDolphins} vs ${avgKoalas})`)
} else if (2 * avgDolphins <= avgKoalas) {
console.log(`Koalas win (${avgKoalas} vs ${avgDolphins})`)
} else {
console.log("No team wins!");
}
}

checkWinner(avgDolphins, avgKoalas);

avgKoalas = calcAverage(23, 34, 27);
avgDolphins = calcAverage(85, 54, 41);

checkWinner(avgDolphins, avgKoalas);

//coding challenge 2
const calcTip = (bill) => {
return bill >=50 && bill <= 300 ? 0.15 * bill : 0.20 * bill;
}

console.log(calcTip(100));

const bills = [125, 555, 44];
const tips = [calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])];
const totals = [bills[0] + tips[0], bills[1] + tips[1], bills[2] + tips[2]];

console.log(bills);
console.log(tips);
console.log(totals);

//coding challenge 3
const mark = {
fullName: "Mark Miller",
mass: 78,
height: 1.69,
calcBMI: function () {
this.bmi = this.mass / this.height ** 2;
return this.bmi;
}
}

const john = {
fullName: "John Smith",
mass: 92,
height: 1.95,
calcBMI: function () {
this.bmi = this.mass / this.height ** 2;
return this.bmi;
}
}

mark.calcBMI();
john.calcBMI();

if (mark.bmi > john.bmi) {
console.log(`${mark.fullName}'s BMI (${mark.bmi}) is higher than ${john.fullName}'s BMI (${john.bmi}).`)
} else {
console.log(`${john.fullName}'s BMI (${john.bmi}) is higher than ${mark.fullName}'s BMI (${mark.bmi}).`)
}

//coding challenge 4

const billz = [22, 295, 176, 440, 37, 105, 10, 1100, 86, 52];
const tipz = [];
const totalz = [];

for (let i = 0; i < billz.length; i++) {
tipz.push(calcTip(billz[i]));
totalz.push(billz[i] + tipz[i]);
}

console.log(billz, tipz, totalz);

//Bonus

const calculateAverage = function(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum / arr.length;
};

console.log(calculateAverage(totalz));

1 change: 1 addition & 0 deletions 02-Fundamentals-Part-2/starter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
<body>
<h1>JavaScript Fundamentals – Part 2</h1>
<script src="script.js"></script>
<script src="coding_challenge.js"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions 02-Fundamentals-Part-2/starter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';
//strict mode activated as long as it's the first line of code

let hasDriversLicense = false;
const passTest = true;

if (passTest) {
hasDriversLicense = true;
}

//Functions

function logger(name) {
console.log(`My name is ${name}`);
}

logger("Betty"); //calling, invoking, running
logger("Robin");

//name is a parameter but Betty is an argument

const jonas = {
birthyr: 1991,
calcAge: function() {
console.log(this);
return 2037 - this.birthyr;
}
}

console.log(jonas.calcAge());
console.log(jonas['calcAge']());
15 changes: 15 additions & 0 deletions 03-Developer-Skills/starter/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Remember, we're gonna use strict mode in all scripts now!
'use strict';

//challenge 1

const arr = [17, 21, 23];

const printForecast = function(arr) {
let days = 0;
let string = "";
for (let i = 0; i < arr.length; i++) {
days++;
string += `... ${arr[i]} degC in ${days} days `;
}
return string;
};

console.log(printForecast(arr));
50 changes: 50 additions & 0 deletions 05-Guess-My-Number/starter/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
'use strict';

let secretNumber = Math.floor(Math.random() * 20) + 1;

let score = 20;
document.querySelector('.score').textContent = score;
let highScore = 0;
document.querySelector('.highscore').textContent = highScore;

const displayMessage = function (message) {
document.querySelector('.message').textContent = message;
}

document.querySelector('.check').addEventListener('click', () => {
const guess = Number(document.querySelector('.guess').value);
document.querySelector('.number').textContent = '?'
if (!guess) {
document.querySelector('.message').textContent = 'Type a number!';
} else if (guess === secretNumber){
document.querySelector('.score').textContent = score;
document.querySelector('.number').textContent = secretNumber;
document.querySelector('body').style.backgroundColor = '#60b347';
displayMessage('You won the game!');
if (score > highScore) {
highScore = score;
document.querySelector('.highscore').textContent = highScore;
}
} else {
score--;
document.querySelector('.score').textContent = score;
if (score === 0) {
displayMessage("GAME OVER!");
} else if (guess > secretNumber) {
displayMessage('Too high, try again!');
} else if (guess < secretNumber) {
displayMessage('Too low, try again!');
}
}
})

//coding challenge 1

document.querySelector('.again').addEventListener('click', () => {
score = 20;
secretNumber = Math.floor(Math.random() * 20) + 1;
displayMessage("Start guessing...");
document.querySelector('body').style.backgroundColor = '#222';
document.querySelector('.score').textContent = score;
document.querySelector('.number').textContent = '?';
document.querySelector('.guess').value = '';
})
29 changes: 29 additions & 0 deletions 06-Modal/starter/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
'use strict';

const modal = document.querySelector('.modal');
const overlay = document.querySelector('.overlay');
const btnCloseModal = document.querySelector('.close-modal');
const btnsOpenModal = document.querySelectorAll('.show-modal');
console.log(btnsOpenModal);

const closeModal = function () {
modal.classList.add('hidden');
overlay.classList.add('hidden');
}
const showModal = function() {
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
}

btnsOpenModal.forEach((button) =>
button.addEventListener('click', showModal));

btnCloseModal.addEventListener('click', closeModal);

overlay.addEventListener('click', closeModal);

document.addEventListener('keydown', (e) => {
console.log(e.key);
if (e.key === 'Escape' && !modal.classList.contains('hidden')) {
closeModal();
}
})
Loading