Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.
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
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;

Choose a reason for hiding this comment

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

For readability try to use full words unless it is a very well recognised acronym like ID for example
studentPercentile

var mentorpercentile = numberOfMentors/23*100;

Choose a reason for hiding this comment

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

use camelCase mentorPercentile

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);

Choose a reason for hiding this comment

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

use full name - totalPrice :)

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