Skip to content
This repository was archived by the owner on Jan 14, 2024. 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 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 JavaScript!");
console.log("Happy Coding!");
10 changes: 10 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Start by creating a variable `greeting`
var greeting = "Hello world";

console.log(greeting);

var greeting = "Hello world";

console.log(greeting);

var greeting = "Hello world";

console.log(greeting);

4 changes: 3 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

const message = "This is a string."
let messageType = "type of message";
console.log(message);

5 changes: 4 additions & 1 deletion 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`
const greetingStart = "Hello, my name is ";
const name = "Abdi";

console.log(message);
const greeting = greetingStart + name;
console.log(greeting);
4 changes: 3 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

const name = "Abdi";
const nameLength = name.length;
const message = `My name is ${name} and my name is ${nameLength} characters long`;
console.log(message);
12 changes: 10 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const name = " Daniel ";
// const name = " Daniel ";

const name = "Abdi";
const nameLength = name.length;
const message = `My name is ${name} and my name is ${nameLength} characters long`;




console.log(message.trim());

console.log(message);
6 changes: 6 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
const numberOfStudents = 15;
const numberOfMentors = 8;
const Total = numberOfStudents + numberOfMentors;
console.log('number of studets is : ' + numberOfStudents)
console.log('number of Mentors is : ' + numberOfMentors)
console.log('Total number of students and mentors: ' + Total)
13 changes: 11 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let numberOfStudents = 15;
let numberOfMentors = 8;
let total = numberOfMentors + numberOfStudents;
let percentageOfStudents = (numberOfStudents / total) * 100;
let percentageOfMentors = (numberOfMentors / total) * 100;
let roundedPercentageOfStudents = Math.round(percentageOfStudents);
let roundedPercentageOfMentors = Math.round(percentageOfMentors);
let message1 = "Percentage students: " + roundedPercentageOfStudents + "%";
let message2 = "Percentage mentors: " + roundedPercentageOfMentors + "%";
console.log(message1);
console.log(message2);
1 change: 1 addition & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);
Expand Down
1 change: 1 addition & 0 deletions 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
11 changes: 7 additions & 4 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
}

function multiply(a, b) {
// Calculate the result of the function and return it
return a * b;
}


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

let result = multiply (10,20);
console.log(result);
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first
function divide(a,b) {
return a/b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a thought, what would happen if b = 0? Your code would try and execute a / 0 - try this and see what happens. This leads onto a nice way of programming called "defensive programming"

}

var result = divide(3, 4);

console.log(result);
console.log(result);
5 changes: 4 additions & 1 deletion 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");
let greeting = createGreeting("Abdi");

console.log(greeting);
7 changes: 5 additions & 2 deletions 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 total(a, b) {
return a + b;

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

let sum = total(14, 121);
console.log(sum);
7 changes: 5 additions & 2 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function here

const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, age) {
return `Hello, my name is ${name} and I'm ${age} years old`;

}
const greeting = createLongGreeting("Abdi", 30);

console.log(greeting);
8 changes: 8 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
function uppercaseNames(name) {
return name.toUpperCase();
}
console.log("HELLO " + uppercaseNames(mentor1));
console.log("HELLO " + uppercaseNames(mentor2));
console.log("HELLO " + uppercaseNames(mentor3));
console.log("HELLO " + uppercaseNames(mentor4));
console.log("HELLO " + uppercaseNames(mentor5));
10 changes: 8 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

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



/*
CURRENCY CONVERSION
Expand All @@ -15,7 +19,9 @@ function convertToUSD() {}
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/

function convertToBRL() {}
function convertToBRL(price) {
return Number(((price * 0.99) *5.7).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
16 changes: 8 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
the final result to the variable goodCode
*/

function add() {

function add(teamOne,teamTwo) {
return teamOne + teamTwo;
}

function multiply() {

function multiply(teamOne,teamTwo) {
return teamOne * teamTwo;
}

function format() {

function format(team) {
return `£${team}`
}

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 */

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 Down
21 changes: 20 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**

Let's peer into the future using a Magic 8 Ball!
https://en.wikipedia.org/wiki/Magic_8-Ball
Expand Down Expand Up @@ -47,6 +47,9 @@
// and return the answer.
function shakeBall() {
//Write your code in here
console.log('The ball has shaken!')
let randomIndex = Math.floor(Math.random() * allAnswers.length)
return allAnswers[randomIndex]
}

/*
Expand All @@ -60,7 +63,23 @@ function shakeBall() {
*/
function checkAnswer(answer) {
//Write your code in here
if (veryPositiveAnswers.includes(answer)) {
return 'very positive'
} else if (positiveAnswers.includes(answer)) {
return 'positive'
} else if (negativeAnswers.includes(answer)) {
return 'negative'
} else if (veryNegativeAnswers.includes(answer)) {
return 'very negative'
}
}
const foo = shakeBall()
const bar = checkAnswer(foo)
console.log(bar)





/*
==================================
Expand Down
22 changes: 12 additions & 10 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,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 getTotal(a, b) {
total = a ++ b;

return "The total is total";
}
// console.log(addNumbers(2,3,4));
function introduceMe(myName, age){
return `Hello, my name is ${myName} and I am ${age} years old`;
}
// console.log(introduceMe(“Abdi”, 25));

function getTotal(a, b) {
total = a + b;
return `The total is ${total}`;
}
// console.log(getTotal(10, 20));

/*
===================================================
Expand Down
7 changes: 4 additions & 3 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// 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 getStringLength(word) {
return "word".length();
return word.length;
}

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

return a * b * c;
}

/*
Expand Down
4 changes: 4 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ function combine2Words(word1, word2) {
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 this function is expected to return.

return firstWord + " " + secondWord + " " + thirdWord;
}



/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
21 changes: 19 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
A business requires a program that calculates how much the price of a product is including sales tax
Sales tax is 20% of the price of the product.
*/
function calculateSalesTax(priceproduct) {
return (priceproduct * 1.2);
}

function calculateSalesTax() {}


// function calculateSalesTax (cost) {
// const tax = 0.2 * cost
// return tax + cost
// return cost * 1.2
// }
// console.log(calculateSalesTax(10));
/*
CURRENCY FORMATTING
===================
Expand All @@ -16,9 +25,17 @@ function calculateSalesTax() {}

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/
function addTaxAndFormatCurrency(priceproduct) {
return "£"+calculateSalesTax(priceproduct).toFixed(2);

function addTaxAndFormatCurrency() {}
}


// function addTaxAndFormatCurrency (itemcost) {
// const total = calculateSalesTax(itemcost)
// const twoDecimal = total.tofixed(2)
// return '£'+ twoDecimal
// }
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
Loading