Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Js/week 3/berhane #86

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
112402f
exercise done B-hello-world
bireworld Jun 19, 2020
82da683
exercise done C-variables
bireworld Jun 19, 2020
375a878
exercise done D-strings
bireworld Jun 19, 2020
a6f2b32
exercise done E-strings-concatenation
bireworld Jun 19, 2020
2d5a4e4
exercise1 done F-strings-method
bireworld Jun 19, 2020
ee55d15
exercise2 done F-strings-method
bireworld Jun 19, 2020
870aa1c
exercise done G-numbers
bireworld Jun 19, 2020
3e8e82c
exercise done I-floats
bireworld Jun 19, 2020
8373dd5
exercise done I-floats update
bireworld Jun 19, 2020
f5bc224
exercise done J-functions
bireworld Jun 19, 2020
45bbcb7
exercise done J-functions
bireworld Jun 19, 2020
ca44007
exercise2 done J-functions
bireworld Jun 19, 2020
4b56746
exercise done K-functions-parameters
bireworld Jun 19, 2020
455ba21
exercise2 done K-functions-parameters
bireworld Jun 19, 2020
dd3dd6d
exercise3 done K-functions-parameters
bireworld Jun 19, 2020
fe488ea
exercise4 done K-functions-parameters
bireworld Jun 19, 2020
4d43363
exercise5 done K-functions-parameters
bireworld Jun 19, 2020
64e0da9
syntax corrected
bireworld Jun 19, 2020
8c623d6
logic error corrected
bireworld Jun 20, 2020
01f6bf6
function output error corrected
bireworld Jun 20, 2020
3bf68ab
tax calcultated
bireworld Jun 20, 2020
5e88c3f
currency conversion done
bireworld Jun 21, 2020
02b63aa
piping done
bireworld Jun 21, 2020
dddd5b2
magic 8 ball done
bireworld Jun 22, 2020
066e5e3
boolean exercise done
bireworld Jun 22, 2020
c21646c
comparison-operator done
bireworld Jun 22, 2020
0dd82d0
predicate exercise done
bireworld Jun 23, 2020
1d6f9ce
conditionals done
bireworld Jun 23, 2020
bcba34c
week-2 fix functio done
bireworld Jun 24, 2020
2249b04
function creation done
bireworld Jun 26, 2020
253bf68
playing computer done
bireworld Jun 26, 2020
5e92931
sorting algot=rith done
bireworld Jun 26, 2020
ca482f0
oxygen level completed
bireworld Jun 29, 2020
bcc14f7
Space colonies completed
bireworld Jul 1, 2020
32a3830
H array methods exercise2 completed
bireworld Jul 2, 2020
f286309
H array methods exercise2 completed
bireworld Jul 2, 2020
844c93d
H array methods exercise completed
bireworld Jul 2, 2020
0ce0c4d
H array methods exercise3 completed
bireworld Jul 2, 2020
35d47e3
G array methods exercise completed
bireworld Jul 2, 2020
670825d
G array methods exercise2 completed
bireworld Jul 2, 2020
381a1ef
F array-forEach exercise completed
bireworld Jul 2, 2020
ea65690
bush berries completed
bireworld Jul 5, 2020
a52effb
eligible students completed
bireworld Jul 5, 2020
9916fde
lane-names completed
bireworld Jul 5, 2020
62d3fb7
password-validator completed
bireworld Jul 6, 2020
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
3 changes: 2 additions & 1 deletion week-1/1-exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log("Hello world");
console.log("Hello world. I just started learning javascript");
console.log(2020);
4 changes: 3 additions & 1 deletion week-1/1-exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

var greeting = "Hello World!";
console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 3 additions & 0 deletions week-1/1-exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
var message = "This is a string";
var messageType = typeof message;

console.log(messageType); // logs 'string'
console.log(message);
6 changes: 5 additions & 1 deletion week-1/1-exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
var greetingStart = "Hello, my name is ";
var name = "Berhane";

console.log(message);
var greeting = greetingStart + name;

console.log(greeting); // Logs "Hello, my name is Daniel"
5 changes: 4 additions & 1 deletion week-1/1-exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`

var name = "Berhane";
var nameLength = name.length;
var message = "My name is " + name +" and my name is " + nameLength + " characters long"
console.log(nameLength); // Logs 6
console.log(message);
6 changes: 3 additions & 3 deletions week-1/1-exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const name = " Daniel ";

console.log(message);
const name = " My name is Berhane and my name is 7 characters long ";
name.trim();
console.log(name);
4 changes: 4 additions & 0 deletions week-1/1-exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = numberOfStudents + numberOfMentors;
console.log("Total numnber of students and mentors:" + sum);
7 changes: 7 additions & 0 deletions week-1/1-exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var stuPercentile = numberOfStudents/23*100;
var mentorpercentile = numberOfMentors/23*100;
stuPercentile = Math.round(stuPercentile);
mentorpercentile = Math.round(mentorpercentile);
console.log("Percentage Students:" +stuPercentile + "%" );
console.log("Percentage Mentors:" + mentorpercentile + "%");

6 changes: 5 additions & 1 deletion week-1/1-exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);

var result2 = halve(32);
var result3 = halve(3);
console.log(result);
console.log(result2);
console.log(result3);
1 change: 1 addition & 0 deletions week-1/1-exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
3 changes: 2 additions & 1 deletion week-1/1-exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1,num2) {
// Calculate the result of the function and return it
return num1 * num2;
}

// Assign the result of calling the function the variable `result`
Expand Down
5 changes: 5 additions & 0 deletions week-1/1-exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Declare your function first
function divide(num1, num2) {
// Calculate the result of the function and return it
return num1 / num2;
}

// Assign the result of calling the function the variable `result`
var result = divide(3, 4);

console.log(result);
3 changes: 3 additions & 0 deletions week-1/1-exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Write your function here
function createGreeting(name){
return "Hello, my name is " + name;
}

var greeting = createGreeting("Daniel");

Expand Down
5 changes: 5 additions & 0 deletions week-1/1-exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Declare your function first
function addition(num1, num2) {
return num1 + num2;
}

sum = addition(13, 124);

// Call the function and assign to a variable `sum`

Expand Down
4 changes: 4 additions & 0 deletions week-1/1-exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Declare your function here
function createLongGreeting(name, age){
return "Hello, my name is " + name + " and I'm " + age + " years old"

}

const greeting = createLongGreeting("Daniel", 30);

Expand Down
19 changes: 10 additions & 9 deletions week-1/2-mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
function addNumbers(a, b, c) {
return a + b + c;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";
function introduceMe(name, age){
return "Hello, my name is " + name + " and I am " + age + " years old";
}

function getAddition(a, b) {
total = a ++ b
function getRemainder(a, b) {


// Use string interpolation here
return "The total is %{total}"
return `The remainder is ${a%b}`;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand All @@ -23,12 +24,12 @@ function getAddition(a, b) {
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED" ;
} else {
status = "FAILED"
status = "FAILED" ;
}

console.log(`${test_name}: ${status}`)
console.log(`${test_name}: ${status}`) ;
}

test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13)
Expand Down
8 changes: 4 additions & 4 deletions week-1/2-mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
return word.trim();
}

function getWordLength(word) {
return "word".length()
return word.length;
}

function multiply(a, b, c) {
a * b * c;
return;

return a * b * c;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
6 changes: 4 additions & 2 deletions week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Add comments to explain what this function does. You're meant to use Google!
function getNumber() {
return Math.random() * 10;
return Math.random() * 10; // returns a random integer from 0 to 9

}

// Add comments to explain what this function does. You're meant to use Google!
function s(w1, w2) {
return w1.concat(w2);
return w1.concat(w2); // concatenates w1(string 1) with w2(string 2)
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together
// Look at the test case below to understand what to expect in return
return firstWord +" " + secondWord +" "+ thirdWord;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
13 changes: 11 additions & 2 deletions week-1/2-mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(productPrice) {

var salesTax = 0.2 * productPrice;
return productPrice+salesTax;

}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +22,11 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function formatCurrency() {}
function formatCurrency(price) {
var totPrice = calculateSalesTax(price);
totPrice = totPrice.toFixed(2);
return "£"+totPrice;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
14 changes: 12 additions & 2 deletions week-1/3-extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(amountPound) {
var amountUSD = amountPound*1.4
return amountUSD
}

/*
CURRENCY FORMATTING
Expand All @@ -16,7 +19,14 @@ function convertToUSD() {}
Find a way to add 1% to all currency conversions (think about the DRY principle)
*/

function convertToBRL() {}
function convertToBRL(amountInPound) {

var amountBRL = amountInPound * 5.7
amountBRL += amountBRL*0.01
return amountBRL

}
console.log(convertToBRL(30))

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
37 changes: 19 additions & 18 deletions week-1/3-extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@
the final result to the variable goodCode
*/

function add() {

function add(num1, num2) {
return ((num1*10) + (num2*10))/10;
}

function multiply() {

function multiply(num1, num2) {
return num1 * num2;
}

function format() {

function format(num) {
return "£" + num;
}

const startingValue = 2
const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
/* we have easier ways applying the already created functions for more flexibility */
let badCode = "£" + add(startingValue, 10) * 2;

/* BETTER PRACTICE */

let goodCode =
let goodCode = format(multiply(add(startingValue, 10), 2));

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand All @@ -46,17 +47,17 @@ To run these tests type `node 2-piping.js` into your terminal
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED"
status = "PASSED";
} else {
status = "FAILED"
status = "FAILED";
}

console.log(`${test_name}: ${status}`)
console.log(`${test_name}: ${status}`);
}

test('add function - case 1 works', add(1,3) === 4)
test('add function - case 2 works', add(2.4,5.3) === 7.7)
test('multiply function works', multiply(2,3) === 6)
test('format function works', format(16) === "£16")
test('badCode variable correctly assigned', badCode === "£24")
test('goodCode variable correctly assigned', goodCode === "£24")
test("add function - case 1 works", add(1, 3) === 4);
test("add function - case 2 works", add(2.4, 5.3) === 7.7);
test("multiply function works", multiply(2, 3) === 6);
test("format function works", format(16) === "£16");
test("badCode variable correctly assigned", badCode === "£24");
test("goodCode variable correctly assigned", goodCode === "£24");
25 changes: 22 additions & 3 deletions week-1/3-extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,36 @@ Very doubtful.

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {}
function shakeBall(answer) {

console.log("The ball has shaken!")

return "The ball has shaken!"

}

// The answer should come from shaking the ball
let answer;
let answer = ["very positive", "positive", "negative", "very negative"];

// When checking the answer, we should tell someone if the answer is
// - very positive
// - positive
// - negative
// - very negative
function checkAnswer() {}
function checkAnswer() {
for(let i=0;i<answer.length;i++)
return answer[i]
}

// console.log(answer[x])









/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
3 changes: 3 additions & 0 deletions week-2/1-exercises/B-boolean-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/

var codeYourFutureIsGreat = true;
var mozafarIsCool = false;
var calculationCorrect = true;
var moreThan10Students = false;

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
6 changes: 3 additions & 3 deletions week-2/1-exercises/C-comparison-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

var studentCount = 16;
var mentorCount = 9;
var moreStudentsThanMentors; // finish this statement
var moreStudentsThanMentors = true; // finish this statement

var roomMaxCapacity = 25;
var enoughSpaceInRoom; // finish this statement
var enoughSpaceInRoom = true; // finish this statement

var personA = "Daniel";
var personB = "Irina";
var sameName; // finish this statement
var sameName = false; // finish this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
Loading