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
1 change: 1 addition & 0 deletions 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("Java is fun");
2 changes: 1 addition & 1 deletion week-1/1-exercises/C-variables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The program above will print "Hello world" to the console. Notice how it uses th
* Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log)
* Print your `greeting` to the console 3 times

> Remember: to run this exercise you must change directory to the `D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`.
> Remember: to run this exercise you must change directory to the `cd D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`.

## Expected result

Expand Down
3 changes: 3 additions & 0 deletions week-1/1-exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `greeting`
let greeting ="Hello world"

console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 4 additions & 0 deletions week-1/1-exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`

let message = "Some string";
let messagetype = typeof message;
console.log(message);
console.log(messagetype);

5 changes: 4 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,6 @@
// Start by creating a variable `message`
var greeting = 'Hello, my name is ';
var firstName = 'Hussein';
var intro = greeting + firstName

console.log(message);
console.log(intro);
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 = "Hussein";
var namelength = name.length;
console.log("My name is Hussein and my name is " + name.length + " characters long" );


console.log(message);
7 changes: 4 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,4 @@
const name = " Daniel ";

console.log(message);
const name = " Hussein";
var namelength = name.length;
var message = "My name is Hussein and my name is " + name.length + " characters long";
console.log(message.trim() );
7 changes: 7 additions & 0 deletions week-1/1-exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = numberOfStudents + numberOfMentors;
console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total numnber of students and mentors: " + sum);

6 changes: 6 additions & 0 deletions week-1/1-exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = numberOfStudents + numberOfMentors;
var studentPercentage = Math.round((numberOfStudents/sum) * 100);
var mentorsPercentage = Math.round((numberOfMentors/sum) * 100);

console.log("Percentage students: " + studentPercentage + "%");
console.log("Percentage mentors: " + mentorsPercentage + "%");
2 changes: 1 addition & 1 deletion week-1/1-exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function halve(number) {
// complete the function here
return number/2
}

var result = halve(12);
Expand Down
2 changes: 1 addition & 1 deletion week-1/1-exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function triple(number) {
// complete function here
return number * 3;
}

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

// Assign the result of calling the function the variable `result`
Expand Down
3 changes: 3 additions & 0 deletions week-1/1-exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Declare your function first
function divide(a,b){
return a / b;
}

var result = divide(3, 4);

Expand Down
5 changes: 4 additions & 1 deletion week-1/1-exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Write your function here
function createGreeting(name){
return "Hello, my name is " + name;
}

var greeting = createGreeting("Daniel");
var greeting = createGreeting("Hussein");

console.log(greeting);
5 changes: 4 additions & 1 deletion week-1/1-exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function first

function addation(a,b){
return a + b;
}
var sum = addation(13,124);
// Call the function and assign to a variable `sum`

console.log(sum);
5 changes: 4 additions & 1 deletion week-1/1-exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +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);
const greeting = createLongGreeting("Hussein", 30);

console.log(greeting);
27 changes: 22 additions & 5 deletions week-1/1-exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

//Calculating the percentage of students
function percentStdts(numOfStudents){
return Math.round(numOfStudents / 23 * 100);
}
function message(numOfStudents){
var value = percentStdts(numOfStudents);
return "Percentage of students: " + value + "%";
}
console.log(message(15));

//Calculating the percentage of mentors
function percentMentors(numOfMentors){
return Math.round(numOfMentors / 23 * 100);
}
function mentorsMessage(numOfMentors){
var mentorsValue = percentMentors(numOfMentors);
return "Percentage of students: " + mentorsValue + "%";
}
console.log(mentorsMessage(8));


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

// 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) {
var remainder = a % b;

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

/* ======= TESTS - DO NOT MODIFY ===== */
//
Expand Down
7 changes: 3 additions & 4 deletions week-1/2-mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// 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
9 changes: 9 additions & 0 deletions week-1/2-mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// Add comments to explain what this function does. You're meant to use Google!

/* This is a random numbers generating function that give a random number between
0 and 9 (both included). */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pretty much there! It's possible to generate a random number less than 10 here but greater than 9.

function getNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!

/* This is a method used to combine arrays into one array. The array before concat() (w1) will be placed first in the
new array. And the array inside the parenthesis (w2) will be placed last. */
function s(w1, w2) {
return w1.concat(w2);
}

function concatenate(firstWord, secondWord, thirdWord) {

return `${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
}
Expand Down
11 changes: 9 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,11 @@
Sales tax is 20% of the price of the product
*/

function calculateSalesTax() {}
function calculateSalesTax(price) {
var priceAfterTax = (price * 0.2) + price;
return priceAfterTax;

}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +21,10 @@ 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 finalPrice = calculateSalesTax(price);
return `£${finalPrice.toFixed(2)}`
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
8 changes: 6 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,9 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(pounds) {
return pounds * 1.4;
}

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

function convertToBRL() {}
function convertToBRL(pound) {
return (pound * 5.7) * 1.01;
}

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

function add() {

function add(a, b) {
return a + b;
}

function multiply() {

function multiply(c, d) {
return c * d;
}

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 =
let badCode = format(multiply(add(startingValue, 10), 2));



/* BETTER PRACTICE */

Expand Down